<template>
  <div class="moments-container">
    <PageHeader height="50vh" :customTexts="['说说 | 日常划水和思考聚集地', '始于代码，不止于代码。']" :backgroundChangeInterval="30000"
      :imageSourcesConfig="['ysz']" />
    <div class="main-content">
      <!-- 新增说说按钮 -->
      <div class="add-moment-btn-section">
        <div class="add-moment-btn-container">
          <div class="add-moment-btn" @click="handleAddMomentClick">
            <i class="fas fa-feather-alt"></i>
            <span>发布说说</span>
            <span class="btn-shine"></span>
          </div>
        </div>
        <div class="section-divider">
          <span>说说墙</span>
        </div>
      </div>

      <!-- 说说列表 -->
      <div class="moments-list" v-loading.fullscreen.lock="loading" element-loading-text="加载说说中..."
        element-loading-background="rgba(255, 255, 255, 0.8)" element-loading-spinner="el-icon-loading">
        <template v-if="!loading && moments.length === 0">
          <div class="no-moments-tip">
            <i class="el-icon-chat-dot-round"></i>
            <p>暂无说说内容，快来发布第一条吧！</p>
            <el-button type="primary" @click="handleAddMomentClick" size="small" icon="el-icon-plus" round>
              去发布说说
            </el-button>
          </div>
        </template>
        <div v-for="moment in moments" :key="moment.id" class="moment-item" :data-moment-id="moment.id">
          <div class="user-avatar">
            <el-popover placement="top-start" :width="300" trigger="hover" :hide-after="0">
              <template #reference>
                <el-avatar :size="50" :src="moment.avatar" :key="moment.avatar" class="avatar"
                  @click="goToUserPage(moment.userId)" />
              </template>
              <UserProfileCard :user-id="moment.userId" />
            </el-popover>
            <div class="mobile-user-info">
              <span class="name" @click="goToUserPage(moment.userId)">{{ moment.nickname }}</span>
              <!-- 在说说时间显示部分修改 -->
              <!-- 原始发布时间显示 -->
              <div class="moment-time-container" v-if="!moment.updateTime || moment.updateTime === moment.createTime">
                <div class="moment-time" :title="formatFullTime(moment.createTime)">
                  <i class="el-icon-time"></i>
                  <span class="time-text">{{ formatCombinedTime(moment.createTime) }}</span>
                </div>
              </div>

              <!-- 更新时间显示 -->
              <div class="moment-time-container updated" v-else>
                <div class="moment-time" :title="formatFullTime(moment.createTime)">
                  <i class="el-icon-time"></i>
                  <span class="time-text">{{ formatCombinedTime(moment.createTime) }}</span>
                </div>
                <div class="moment-time update-time" :title="formatFullTime(moment.updateTime)">
                  <i class="el-icon-refresh"></i>
                  <span class="time-text">更新于 {{ formatCombinedTime(moment.updateTime) }}</span>
                </div>
              </div>
            </div>
          </div>
          <div class="moment-main">
            <div class="moment-header">
              <span class="name user-link" @click="goToUserPage(moment.userId)">{{ moment.nickname }}</span>
              <!-- 原始发布时间显示 -->
              <div class="moment-time-container" v-if="!moment.updateTime || moment.updateTime === moment.createTime">
                <div class="moment-time" :data-full-time="formatFullTime(moment.createTime)">
                  <i class="el-icon-time"></i>
                  <span class="time-text">{{ formatCombinedTime(moment.createTime) }}</span>
                </div>
              </div>

              <!-- 更新时间显示 -->
              <div class="moment-time-container updated" v-else>
                <div class="moment-time" :data-full-time="formatFullTime(moment.createTime)">
                  <i class="el-icon-time"></i>
                  <span class="time-text">{{ formatCombinedTime(moment.createTime) }}</span>
                </div>
                <div class="moment-time update-time" :data-full-time="formatFullTime(moment.updateTime)">
                  <i class="el-icon-refresh"></i>
                  <span class="time-text">更新于 {{ formatCombinedTime(moment.updateTime) }}</span>
                </div>
              </div>
            </div>
            <div class="moment-content-wrapper">
              <!-- 添加点击事件到内容区域，用于跳转到详情页 -->
              <div class="moment-content" v-html="renderContent(moment.content)"
                :class="{ 'collapsed': !moment.expanded && isContentTooLong(moment.content) }"
                @click.stop="tryToggleExpand(moment)" v-auto-link-jump="{ exclude: ['.no-jump'] }"></div>
              <!-- 展开/收缩按钮 -->
              <div v-if="isContentTooLong(moment.content)" class="expand-collapse-btn"
                @click.stop="toggleExpand(moment)">
                <span>{{ moment.expanded ? '收起内容' : '展开全文' }}</span>
                <i :class="moment.expanded ? 'el-icon-arrow-up' : 'el-icon-arrow-down'"></i>
                <div class="expand-btn-shine"></div>
              </div>
              <!-- 说说图片展示 -->
              <div class="moment-images" v-if="moment.images && moment.images !== ''">
                <!-- 限制最多显示9张图片 -->
                <div v-for="(img, index) in parseImages(moment.images).slice(0, 9)" :key="index" class="image-container"
                  @click.stop="previewImage(parseImages(moment.images), index)">
                  <img v-lazy="img" :key="img" alt="说说图片" />
                </div>
              </div>
              <!-- 添加一个专门用于跳转的区域 -->
              <div class="moment-detail-link" @click.stop="goToDetail(moment.id)">
                查看详情 <i class="el-icon-right"></i>
              </div>
            </div>
            <!-- 说说操作区域 -->
            <div class="moment-actions" @click.stop>
              <!-- 点赞按钮 -->
              <div class="action-item" @click="handleLikeMoment(moment)">
                <!-- <i :class="['fas fa-heart', { 'liked': moment.isLiked }]"></i> -->
                <i :class="['far fa-heart', { 'fas fa-heart liked': moment.isLiked }]"></i>
                <span>{{ moment.likeCount || 0 }}</span>
              </div>

              <!-- 评论按钮 -->
              <div class="action-item" @click="showComments(moment.id)">
                <i class="el-icon-chat-line-square"></i>
                <span>{{ moment.commentCount || 0 }}</span>
              </div>

              <!-- 复制按钮 -->
              <div class="action-item">
                <copy-content :content="moment.content" success-text="说说内容已复制" />
              </div>

              <!-- 分享按钮 -->
              <div class="action-item">
                <share-card :content="moment.content" :images="parseImages(moment.images)" :nickname="moment.nickname"
                  :avatar="moment.avatar" :moment-id="moment.id" :create-time="moment.createTime"
                  :update-time="moment.updateTime" />
              </div>
            </div>

            <!-- 评论区域 -->
            <div class="comments-section" v-if="moment.showComments" @click.stop>
              <div class="comments-loading" v-if="moment.commentsLoading">
                <el-skeleton :rows="3" animated />
              </div>
              <div v-else>
                <!-- 评论列表 -->
                <div class="comments-list" v-if="moment.comments && moment.comments.length > 0">
                  <!-- 每个评论项 -->
                  <div v-for="comment in moment.comments" :key="comment.id" class="comment-thread">
                    <!-- 主评论 -->
                    <div class="comment-item">
                      <div class="comment-avatar">
                        <el-popover placement="right-start" :width="300" trigger="hover" :hide-after="0">
                          <template #reference>
                            <el-avatar :size="40" :src="comment.avatar" :key="comment.avatar" alt="用户头像"
                              @click="goToUserPage(comment.userId)" style="cursor: pointer;" />
                          </template>
                          <UserProfileCard :user-id="comment.userId" />
                        </el-popover>
                      </div>
                      <div class="comment-content">
                        <div class="comment-header">
                          <span class="comment-user user-link" @click="goToUserPage(comment.userId)">{{ comment.nickname
                            }}</span>
                          <span class="comment-time" :data-full-time="formatFullTime(comment.createTime)">
                            {{ formatCombinedTime(comment.createTime) }}
                          </span>
                          <!-- <span class="comment-time">{{ formatRelativeTime(comment.createTime) }}</span> -->
                          <!-- 添加删除按钮 - 仅对自己的评论显示 -->
                          <span v-if="userInfo && userInfo.id === comment.userId" class="delete-btn"
                            @click.stop="handleDeleteComment(comment.id, moment.id)">
                            <i class="el-icon-delete"></i>
                          </span>
                        </div>
                        <div class="comment-text">{{ comment.content }}</div>

                        <!-- 评论操作区 -->
                        <div class="comment-actions">
                          <div class="action-btn" @click="handleLikeComment(comment, moment.id)">
                            <!-- <i :class="['el-icon-star-off', { 'liked': comment.isLiked }]"></i> -->
                            <!-- <i :class="['fas fa-heart', { 'liked': comment.isLiked }]"></i> -->
                            <i :class="['far fa-heart', { 'fas fa-heart liked': comment.isLiked }]"></i>
                            <span>{{ comment.likeCount || 0 }}</span>
                          </div>
                          <div class="action-btn" @click="showReplyForm(comment, moment.id)">
                            <i class="el-icon-chat-dot-square"></i>
                            <span>回复</span>
                          </div>
                        </div>

                        <!-- 回复表单 -->
                        <div class="reply-form" v-if="comment.showReplyForm">
                          <el-input v-model="comment.replyContent" type="textarea" :rows="2"
                            :placeholder="'回复 ' + comment.nickname + '...'" resize="none"
                            class="reply-input"></el-input>
                          <div class="form-actions">
                            <el-button size="small" @click="cancelReply(comment)">取消</el-button>
                            <el-button type="primary" size="small" @click="submitReply(comment, moment.id)"
                              :loading="comment.replySubmitting">
                              发表回复
                            </el-button>
                          </div>
                        </div>
                      </div>
                    </div>

                    <!-- 回复列表 -->
                    <div class="replies-list" v-if="comment.children && comment.children.length > 0">
                      <div v-for="reply in comment.children" :key="reply.id" class="reply-item">
                        <div class="reply-avatar">
                          <el-popover placement="right-start" :width="300" trigger="hover" :hide-after="0">
                            <template #reference>
                              <el-avatar :size="30" :src="reply.avatar" :key="reply.avatar" alt="用户头像"
                                @click="goToUserPage(reply.userId)" style="cursor: pointer;" />
                            </template>
                            <UserProfileCard :user-id="reply.userId" />
                          </el-popover>
                        </div>
                        <div class="reply-content">
                          <div class="reply-header">
                            <span class="reply-user user-link" @click="goToUserPage(reply.userId)">{{ reply.nickname
                              }}</span>
                            <span class="reply-to" v-if="reply.replyToUser">
                              回复 <span class="reply-to-name">{{ reply.replyToUser }}</span>
                            </span>
                            <span class="reply-time" :data-full-time="formatFullTime(reply.createTime)">
                              {{ formatCombinedTime(reply.createTime) }}
                            </span>
                            <!-- <span class="reply-time">{{ formatRelativeTime(reply.createTime) }}</span> -->
                            <!-- 添加删除按钮 - 仅对自己的回复显示 -->
                            <span v-if="userInfo && userInfo.id === reply.userId" class="delete-btn"
                              @click.stop="handleDeleteComment(reply.id, moment.id)">
                              <i class="el-icon-delete"></i>
                            </span>
                          </div>
                          <div class="reply-text">{{ reply.content }}</div>

                          <div class="reply-actions">
                            <div class="action-btn" @click="handleLikeComment(reply, moment.id)">
                              <!-- <i :class="['el-icon-star-off', { 'liked': reply.isLiked }]"></i> -->
                              <!-- <i :class="['fas fa-heart', { 'liked': reply.isLiked }]"></i> -->
                              <i :class="['far fa-heart', { 'fas fa-heart liked': reply.isLiked }]"></i>
                              <span>{{ reply.likeCount || 0 }}</span>
                            </div>
                            <div class="action-btn" @click="showReplyForm(reply, moment.id)">
                              <i class="el-icon-chat-dot-square"></i>
                              <span>回复</span>
                            </div>
                          </div>

                          <!-- 回复的回复表单 -->
                          <div class="reply-form" v-if="reply.showReplyForm">
                            <el-input v-model="reply.replyContent" type="textarea" :rows="2"
                              :placeholder="'回复 ' + reply.nickname + '...'" resize="none"
                              class="reply-input"></el-input>
                            <div class="form-actions">
                              <el-button size="small" @click="cancelReply(reply)">取消</el-button>
                              <el-button type="primary" size="small" @click="submitReply(reply, moment.id)"
                                :loading="reply.replySubmitting">
                                发表回复
                              </el-button>
                            </div>
                          </div>
                        </div>
                      </div>
                    </div>
                  </div>
                </div>

                <!-- 无评论提示 -->
                <div class="no-comments" v-else>
                  <i class="el-icon-chat-dot-round"></i>
                  暂无评论，快来发表第一条评论吧
                </div>

                <!-- 评论分页 -->
                <div class="comments-pagination" v-if="moment.commentTotal > moment.commentPageSize">
                  <el-pagination background layout="prev, pager, next" :total="moment.commentTotal"
                    :page-size="moment.commentPageSize" :current-page.sync="moment.commentPage"
                    @current-change="page => loadComments(moment.id, page)"></el-pagination>
                </div>

                <!-- 发表评论表单 -->
                <div class="comment-form">
                  <el-input v-model="moment.commentContent" type="textarea" :rows="3" placeholder="发表你的评论..."
                    resize="none" class="comment-input"></el-input>
                  <div class="form-actions">
                    <el-button type="primary" @click="submitComment(moment)" :loading="moment.commentSubmitting"
                      icon="el-icon-s-promotion">
                      发表评论
                    </el-button>
                  </div>
                </div>
              </div>
            </div>
          </div>
        </div>

        <!-- 分页 -->
        <div class="pagination-box">
          <el-pagination background v-if="moments.length" @current-change="handlePageChange"
            :current-page="params.pageNum" :page-size="params.pageSize" layout="prev, pager, next" :total="total">
          </el-pagination>
        </div>
      </div>
    </div>

    <!-- 新增说说弹窗 -->
    <el-dialog :visible.sync="dialogVisible" :width="dialogWidth" @closed="resetForm" @open="onDialogOpen"
      :destroy-on-close="false" :append-to-body="true" top="10vh"
      :custom-class="'moment-dialog' + (isMobile ? ' is-mobile' : '')" :show-close="false">
      <template #title>
        <div class="moment-dialog__header">
          <el-avatar :size="32" :src="userInfo ? userInfo.avatar : ''" />
          <span class="username">{{ userInfo ? userInfo.nickname : '发布说说' }}</span>
        </div>
        <div class="moment-dialog__close" @click="dialogVisible = false">
          <i class="el-icon-close"></i>
        </div>
      </template>

      <div class="moment-dialog-body-wrapper">
        <div class="moment-dialog__content">
          <div class="editor-container" :class="{ 'mobile-editor': isMobile }">
            <Toolbar style="border-bottom: 1px solid #e8e8e8" :editor="editor" :defaultConfig="toolbarConfig"
              :mode="'default'" />
            <Editor class="editor-content-area" :style="{ height: editorHeight }" v-model="editorContent"
              :defaultConfig="editorConfig" :mode="'default'" @onCreated="onEditorCreated"
              @onChange="handleEditorChange" />
          </div>
          <div class="upload-wrapper">
            <div class="upload-tip">
              <i class="el-icon-info"></i>
              <span>最多可上传9张图片，单张图片不超过5MB</span>
            </div>
            <el-upload class="upload-images" action="#" list-type="picture-card" :http-request="uploadImage"
              :on-remove="handleRemoveImage" :on-preview="handlePreviewUploadImage" multiple :limit="9"
              :file-list="fileList" :on-exceed="handleExceed" accept=".jpg,.jpeg,.png,.gif"
              :class="{ 'is-uploading': uploading }">
              <div>
                <i class="el-icon-plus"></i>
                <div class="upload-text">点击上传</div>
              </div>
            </el-upload>
          </div>
        </div>
        <div class="moment-dialog__footer-custom">
          <el-button @click="dialogVisible = false" :size="isMobile ? 'medium' : 'small'" round>取消</el-button>
          <el-button type="primary" @click="submitMoment" :loading="submitting" :size="isMobile ? 'medium' : 'small'"
            round icon="el-icon-s-promotion">
            发布
          </el-button>
        </div>
      </div>
    </el-dialog>

    <!-- 图片预览 -->
    <mj-image-preview ref="imagePreview" />
  </div>
</template>

<script>
import {
  formatTime,
  formatDetailTime,
  formatCombinedTime
} from '@/utils/time'
// import { getMoments, addMoment } from '@/api/moments'
import {
  getMoments,
  addMoment,
  toggleMomentLike,
  getMomentLikeCount,
  checkMomentLikeStatus,
  addComment,
  replyComment,
  getMomentComments,
  toggleCommentLike,
  checkCommentLikeStatus,
  getMomentDetail,
  getMomentCommentCount,
  deleteComment
} from '@/api/moments'
import { uploadFileApi } from '@/api/file'
import { mapState } from 'vuex'
import { Editor, Toolbar } from '@wangeditor/editor-for-vue'
import '@wangeditor/editor/dist/css/style.css'
import 'highlight.js/styles/vs2015.css' // 导入默认代码高亮主题
import DOMPurify from 'dompurify'
// 导入高亮工具
import highlightUtil, { renderContent, applyHighlighting } from '@/utils/highlight'
// 导入高亮样式
import '@/utils/highlight.css'
// 导入自定义组件
import CopyContent from '@/components/common/CopyContent.vue'
import ShareCard from '@/components/common/ShareCard.vue'
import PageHeader from '@/components/PageHeader/index.vue'
import UserProfileCard from '@/components/UserProfileCard/index.vue'

export default {
  name: 'Moments',
  components: {
    Editor,
    Toolbar,
    CopyContent,
    ShareCard,
    PageHeader,
    UserProfileCard
  },
  data() {
    return {
      moments: [],
      loading: false,
      total: 0,
      params: {
        pageNum: 1,
        pageSize: 10
      },
      // 新增说说相关数据
      dialogVisible: false,
      momentForm: {
        content: '',
        images: []
      },
      // 判断是否为移动端
      isMobile: false,
      // 富文本编辑器相关数据
      editor: null,
      toolbarConfig: {
        excludeKeys: [] // 将在这里动态设置
      },
      editorConfig: {
        placeholder: '分享你的想法...',
        scroll: true,
        maxLength: 50000,
        autoFocus: false,
        MENU_CONF: {
          // 图片上传配置
          uploadImage: {
            maxFileSize: 5 * 1024 * 1024, // 5MB
            allowedFileTypes: ['image/jpeg', 'image/jpg', 'image/png', 'image/gif'],
            maxNumberOfFiles: 10,
            customUpload: async (file, insertFn) => {
              // 检查文件类型和大小
              if (!['image/jpeg', 'image/jpg', 'image/png', 'image/gif'].includes(file.type)) {
                this.$message.error('只能上传 jpg, jpeg, png, gif 格式的图片')
                return
              }

              if (file.size > 5 * 1024 * 1024) {
                this.$message.error('图片大小不能超过5MB')
                return
              }

              const formData = new FormData()
              formData.append('file', file)

              // 显示上传状态
              const loadingInstance = this.$loading({
                lock: true,
                text: '图片上传中...',
                spinner: 'el-icon-loading',
                background: 'rgba(0, 0, 0, 0.7)'
              })

              try {
                const res = await uploadFileApi(formData, 'moment')

                if (res.code === 200) {
                  // 上传成功，插入图片到编辑器
                  insertFn(res.data)
                  this.$message.success('图片上传成功')

                  // 将图片也添加到momentForm.images中
                  if (!this.momentForm.images.includes(res.data)) {
                    this.momentForm.images.push(res.data)
                  }
                } else {
                  this.$message.error(res.msg || '图片上传失败')
                }
              } catch (error) {
                console.error('上传图片失败:', error)
                this.$message.error('图片上传失败，请检查网络连接')
              } finally {
                loadingInstance.close()
              }
            }
          }
        }
      },
      editorContent: '',
      editorHeight: '320px',
      // 其他现有数据
      rules: {
        content: [
          { required: true, message: '请输入说说内容', trigger: 'blur' }
        ]
      },
      fileList: [],
      submitting: false,
      // 图片预览
      previewVisible: false,
      previewUrl: '',
      uploading: false,  // 上传状态标识

      // 新增API相关数据
      momentApiUrl: '/api/moment',
    }
  },
  computed: {
    ...mapState(['userInfo']),
    dialogWidth() {
      // 移动端使用vw单位，桌面端使用固定宽度
      return this.isMobile ? '90vw' : '750px'
    }
  },
  mounted() {
    this.fetchMoments()
    this.checkMobileDevice()
    // 监听窗口大小变化，重新检测是否为移动设备
    window.addEventListener('resize', this.checkMobileDevice)
  },

  beforeDestroy() {
    // 销毁编辑器实例，避免内存泄漏
    if (this.editor != null) {
      this.editor.destroy()
      this.editor = null
    }
    // 移除窗口大小变化监听
    window.removeEventListener('resize', this.checkMobileDevice)
  },

  methods: {
    /**
     * 跳转到说说详情页
     */
    goToDetail(momentId) {
      // 在新标签页中打开
      // const routeUrl = this.$router.resolve({
      //   path: `/moments/${momentId}`
      // });
      // window.open(routeUrl.href, '_blank');
      // // this.$router.push(`/moments/${momentId}`);
      // 如果用户正在选择文字，则不执行跳转
      if (window.getSelection().toString().length > 0) {
        return;
      }
      this.$router.push(`/moments/${momentId}`);
    },
    /**
     * 格式化完整时间（用于鼠标悬停提示）
     */
    formatFullTime(time) {
      if (!time) return '';
      const date = new Date(time);
      return date.toLocaleString('zh-CN', {
        year: 'numeric',
        month: '2-digit',
        day: '2-digit',
        hour: '2-digit',
        minute: '2-digit',
        second: '2-digit',
        hour12: false
      });
    },
    // 使用新的时间格式化函数
    formatCombinedTime,
    formatDetailTime,

    // 点击内容区域的处理
    tryToggleExpand(moment) {
      // 如果用户正在选择文字，则不执行任何操作
      if (window.getSelection().toString().length > 0) {
        return;
      }
      // 如果内容过长且当前是收缩状态，则展开内容
      if (!moment.expanded && this.isContentTooLong(moment.content)) {
        this.toggleExpand(moment);
      } else {
        // 否则，跳转到详情页
        this.goToDetail(moment.id);
      }
    },

    // 判断内容是否过长需要收缩
    isContentTooLong(content) {
      if (!content) return false;

      // 移除HTML标签后的纯文本
      const plainText = content.replace(/<[^>]+>/g, '');

      // 检测是否包含代码块
      const hasCodeBlock = /<pre[^>]*>/i.test(content);

      // 如果包含代码块或超过300个字符或5行文本则认为内容较长
      const lineCount = (plainText.match(/\n/g) || []).length;
      return hasCodeBlock || plainText.length > 300 || lineCount > 5;
    },

    // 切换内容的展开/收缩状态
    toggleExpand(moment) {
      // 设置状态
      this.$set(moment, 'expanded', !moment.expanded);

      // 使用下一个渲染周期，确保DOM已更新
      this.$nextTick(() => {
        // 查找当前操作的 moment-item 元素
        const momentEl = document.querySelector(`[data-moment-id="${moment.id}"]`);
        if (momentEl) {
          const content = momentEl.querySelector('.moment-content');
          if (content) {
            if (moment.expanded) {
              content.classList.add('expanding');
              setTimeout(() => {
                content.classList.remove('expanding');
                try {
                  applyHighlighting(content);
                } catch (err) {
                  console.error('应用高亮出错:', err);
                }
                this.processContentLinks(content);
              }, 300);
            } else {
              this.processContentLinks(content);
            }
          }
        }

        // 如果收起，滚动到说说顶部
        if (!moment.expanded) {
          if (momentEl) {
            momentEl.scrollIntoView({ behavior: 'smooth', block: 'center' });
          }
        }
      });
    },

    // 处理内容中的链接
    processContentLinks(contentEl) {
      if (!contentEl) return;

      // 查找内容中的所有链接
      const links = contentEl.querySelectorAll('a');
      links.forEach(link => {
        // 获取链接地址
        const href = link.getAttribute('href');
        if (!href) return;

        // 判断是否为外部链接
        if (this.isExternalLink(href)) {
          // 添加外部链接样式
          link.classList.add('external-link');

          // 移除可能存在的target属性
          link.removeAttribute('target');

          // 移除之前可能添加的事件监听器
          const newLink = link.cloneNode(true);
          link.parentNode.replaceChild(newLink, link);

          // 添加点击事件
          newLink.addEventListener('click', (e) => {
            e.preventDefault();
            e.stopPropagation();

            // 使用全局链接跳转提示框
            if (this.$linkJumpPrompt) {
              this.$linkJumpPrompt.url = href;
              this.$linkJumpPrompt.show();
            } else if (Vue.prototype.$linkJumpPrompt) {
              Vue.prototype.$linkJumpPrompt.url = href;
              Vue.prototype.$linkJumpPrompt.show();
            } else {
              // 如果提示框不可用，直接在新窗口打开
              window.open(href, '_blank', 'noopener,noreferrer');
            }
          });
        }
      });
    },

    // 判断是否为外部链接
    isExternalLink(url) {
      if (!url) return false;

      // 如果是完整的URL（包含协议）
      if (/^https?:\/\//i.test(url)) {
        try {
          const urlObj = new URL(url);
          const currentHost = window.location.hostname;

          // 如果域名不同，则为外部链接
          return urlObj.hostname !== currentHost;
        } catch (e) {
          return false;
        }
      }

      // 如果以//开头（协议相对URL）
      if (url.startsWith('//')) {
        return true;
      }

      // 如果以/开头，则为站内链接
      if (url.startsWith('/')) {
        return false;
      }

      // 如果以#开头，则为页内锚点
      if (url.startsWith('#')) {
        return false;
      }

      // 其他情况，默认为外部链接
      return true;
    },

    // 渲染富文本内容，增强格式支持
    renderContent(content) {
      if (!content) return '';

      try {
        // 使用新的渲染工具
        const processedContent = renderContent(content, {
          markdown: true, // 启用markdown渲染
          codeHighlight: true,
          linkNewWindow: false, // 禁用自动新窗口打开，我们将使用自定义处理
          lazyLoadImages: true,
          purifyHtml: true,
          autoDetectLinks: true, // 启用自动链接识别
          forceMarkdown: false // 如果需要强制使用Markdown渲染，设置为true
        });

        // 在下一个tick中应用代码高亮
        this.$nextTick(() => {
          // 确保在DOM完全更新后再应用高亮
          setTimeout(() => {
            try {
              // 应用高亮和其他增强效果
              applyHighlighting('.moment-content');

              // 处理所有内容元素的链接
              const contentElements = document.querySelectorAll('.moment-content');
              contentElements.forEach(element => {
                this.processContentLinks(element);
              });
            } catch (error) {
              console.error('应用高亮和处理链接失败:', error);
            }
          }, 50);
        });

        return processedContent;
      } catch (error) {
        console.error('渲染内容出错:', error);
        return content; // 如果出错，返回原始内容
      }
    },

    handleAddMomentClick() {
      // 直接使用 userInfo 判断登录状态
      if (this.userInfo) {
        this.openAddMomentDialog()
      } else {
        this.$message.warning('请先登录')
        this.$router.push('/login')
      }
    },

    parseImages(imagesStr) {
      console.log('原始图片数据:', imagesStr);

      // 如果为空，直接返回空数组
      if (!imagesStr || imagesStr === '') return [];

      try {
        // 处理字符串格式的图片数据
        if (typeof imagesStr === 'string') {
          // 如果是JSON格式
          if (imagesStr.startsWith('[') && imagesStr.endsWith(']')) {
            const parsed = JSON.parse(imagesStr);
            console.log('解析后的JSON图片数组:', parsed);
            // 确保不重复
            return [...new Set(parsed)];
          }

          // 如果是逗号分隔的字符串
          const images = imagesStr.split(',').filter(img => img && img.trim() !== '');
          console.log('按逗号分隔后的图片数组:', images);
          // 确保不重复
          return [...new Set(images)];
        }

        // 如果已经是数组
        if (Array.isArray(imagesStr)) {
          console.log('已经是数组的图片数据:', imagesStr);
          // 确保不重复
          return [...new Set(imagesStr)];
        }

        return [];
      } catch (err) {
        console.error('解析图片失败:', err);
        return [];
      }
    },
    /* parseImages(images) {
      if (!images) return []
      // 确保返回的是有效的图片URL数组
      const imageArray = images.split(',').filter(img => img && img.trim() !== '')
      console.log('解析后的图片数组:', imageArray) // 添加调试日志
      return imageArray
      // if (!images) return []
      // return images.split(',').filter(img => img)
    }, */

    // 处理评论数据，转换为QQ风格的层级结构
    // 处理评论数据时确保设置正确的parentId
    /* processCommentsToFlat(moment) {
      if (!moment || !moment.comments) return;
      
      // 创建用户ID到用户信息的映射
      const userMap = new Map();
      
      // 第一步：收集所有用户信息
      moment.comments.forEach(comment => {
        // 存储主评论用户信息
        userMap.set(comment.userId, {
          nickname: comment.nickname,
          avatar: comment.avatar
        });
        
        // 存储回复中的用户信息
        if (comment.children && comment.children.length > 0) {
          comment.children.forEach(reply => {
            userMap.set(reply.userId, {
              nickname: reply.nickname,
              avatar: reply.avatar
            });
          });
        }
      });
      
      // 第二步：处理主评论
      moment.comments.forEach(comment => {
        // 为主评论添加UI状态属性
        this.$set(comment, 'showReplyForm', false);
        this.$set(comment, 'replyContent', '');
        this.$set(comment, 'replySubmitting', false);
        this.$set(comment, 'isMainComment', true);
        this.$set(comment, 'parentId', null); // 主评论没有父评论
        
        // 检查评论点赞状态
        this.checkCommentLikeStatus(comment.id);
        
        // 第三步：处理回复
        if (comment.children && comment.children.length > 0) {
          comment.children.forEach(reply => {
            this.$set(reply, 'showReplyForm', false);
            this.$set(reply, 'replyContent', '');
            this.$set(reply, 'replySubmitting', false);
            this.$set(reply, 'isMainComment', false);
            this.$set(reply, 'parentId', comment.id); // 设置父评论ID为主评论ID
            
            // 设置回复目标用户信息
            if (reply.replyUserId && userMap.has(reply.replyUserId)) {
              const replyToUser = userMap.get(reply.replyUserId);
              this.$set(reply, 'replyToUser', replyToUser.nickname);
            }
            
            // 检查回复点赞状态
            this.checkCommentLikeStatus(reply.id);
          });
        }
      });
    }, */
    // 辅助函数：根据用户ID查找用户
    findUserById(userId, comments) {
      // 先在主评论中查找
      const mainComment = comments.find(c => c.userId === userId);
      if (mainComment) return mainComment;

      // 在回复中查找
      for (const comment of comments) {
        if (comment.children) {
          const childComment = comment.children.find(c => c.userId === userId);
          if (childComment) return childComment;
        }
      }

      return null;
    },
    // 处理评论数据，设置回复关系
    processCommentsToFlat(moment) {
      if (!moment || !moment.comments) return;

      // 创建用户ID到用户信息的映射
      const userMap = new Map();

      // 第一步：收集所有用户信息
      moment.comments.forEach(comment => {
        // 存储主评论用户信息
        userMap.set(comment.userId, {
          nickname: comment.nickname,
          avatar: comment.avatar
        });

        // 存储回复中的用户信息
        if (comment.children && comment.children.length > 0) {
          comment.children.forEach(reply => {
            userMap.set(reply.userId, {
              nickname: reply.nickname,
              avatar: reply.avatar
            });
          });
        }
      });

      // 处理评论和回复
      moment.comments.forEach(comment => {
        // 为评论添加UI状态属性
        this.$set(comment, 'showReplyForm', false);
        this.$set(comment, 'replyContent', '');
        this.$set(comment, 'replySubmitting', false);

        // 处理回复
        if (comment.children && comment.children.length > 0) {
          comment.children.forEach(reply => {
            this.$set(reply, 'showReplyForm', false);
            this.$set(reply, 'replyContent', '');
            this.$set(reply, 'replySubmitting', false);

            // 设置回复目标用户信息
            if (reply.replyUserId && userMap.has(reply.replyUserId)) {
              const replyToUser = userMap.get(reply.replyUserId);
              this.$set(reply, 'replyToUser', replyToUser.nickname);
            }
          });
        }
      });
    },

    // 获取说说列表 添加获取评论数
    async fetchMoments() {
      this.loading = true;
      try {
        const res = await getMoments(this.params);
        if (res.code === 200) {
          // 处理数据，添加必要的UI状态属性
          this.moments = res.data.records.map(moment => ({
            ...moment,
            showComments: false,
            commentsLoading: false,
            comments: [],
            commentPage: 1,
            commentPageSize: 10,
            commentTotal: 0,
            commentContent: '',
            commentSubmitting: false,
            isLiked: false,
            likeCount: 0,
            commentCount: 0,  // 初始化评论数
            expanded: false   // 添加内容展开/收缩状态
          }));
          this.total = res.data.total;

          // 获取每个说说的点赞状态和点赞数
          this.moments.forEach(moment => {
            this.checkMomentLikeStatus(moment.id);
            this.getMomentLikeCount(moment.id);
            this.getMomentCommentCount(moment.id)  // 获取评论数
          });
        }
      } catch (error) {
        console.error('获取说说列表失败:', error);
        this.$message.error('获取说说列表失败');
      } finally {
        this.loading = false;
      }
    },

    handlePageChange(page) {
      this.params.pageNum = page
      this.fetchMoments()
    },

    previewImage(images, index) {
      // 使用图片预览组件的 show 方法
      // this.$refs.imagePreview.show(images, index)
      console.log('预览图片:', images, index) // 添加调试日志
      if (this.$refs.imagePreview) {
        this.$refs.imagePreview.show(images, index)
      } else {
        // 如果图片预览组件不可用，使用简单的预览
        this.previewUrl = images[index]
        this.previewVisible = true
      }
    },

    formatTime(time) {
      return formatTime(time)
    },

    // 格式化相对时间
    formatRelativeTime(dateString) {
      if (!dateString) return '';

      const date = new Date(dateString);
      const now = new Date();
      const diffMs = now - date;
      const diffSec = Math.floor(diffMs / 1000);
      const diffMin = Math.floor(diffSec / 60);
      const diffHour = Math.floor(diffMin / 60);
      const diffDay = Math.floor(diffHour / 24);

      if (diffSec < 60) {
        return '刚刚';
      } else if (diffMin < 60) {
        return `${diffMin}分钟前`;
      } else if (diffHour < 24) {
        return `${diffHour}小时前`;
      } else if (diffDay < 30) {
        return `${diffDay}天前`;
      } else {
        // 超过30天显示具体日期
        return date.toLocaleDateString('zh-CN', {
          year: 'numeric',
          month: '2-digit',
          day: '2-digit'
        }).replace(/\//g, '-');
      }
    },
    // 新增说说相关方法
    openAddMomentDialog() {
      // 再次检查登录状态
      if (!this.userInfo) {
        this.$message.warning('请先登录')
        return
      }

      // 重置表单
      this.momentForm = {
        content: '',
        images: []
      }
      this.fileList = []
      this.editorContent = '' // 确保编辑器内容为空

      // 显示弹窗
      this.dialogVisible = true

      // 确保在下一个 tick 中表单已经渲染
      this.$nextTick(() => {
        if (this.$refs.momentFormRef) {
          this.$refs.momentFormRef.resetFields()
        }

        // 如果编辑器已存在但被销毁，需要重新创建
        if (this.editor === null) {
          console.log('编辑器需要重新初始化')
          // 编辑器将通过@onCreated回调自动初始化
        }
      })
    },

    // 重置表单
    resetForm() {
      if (this.$refs.momentFormRef) {
        this.$refs.momentFormRef.resetFields()
      }

      this.momentForm = {
        content: '',
        images: []
      }
      this.fileList = []
      this.editorContent = '' // 清空编辑器内容

      // 不在此处销毁编辑器，只清空内容
      if (this.editor) {
        try {
          // 清空编辑器内容
          this.editor.clear()
          console.log('编辑器内容已清空，实例保留')
        } catch (error) {
          console.error('清空编辑器失败:', error)
          // 如果清空失败，说明编辑器实例可能已损坏，尝试重建
          this.editor = null
        }
      }
    },

    // 处理超出上传限制
    handleExceed() {
      this.$message.warning('最多只能上传9张图片')
    },

    // 上传图片
    async uploadImage(options) {
      const file = options.file

      // 检查文件类型
      const acceptTypes = ['image/jpeg', 'image/jpg', 'image/png', 'image/gif']
      if (!acceptTypes.includes(file.type)) {
        this.$message.error('只能上传 jpg, jpeg, png, gif 格式的图片')
        return
      }

      // 检查文件大小
      if (file.size > 5 * 1024 * 1024) {
        this.$message.error('图片大小不能超过5MB')
        return
      }

      const formData = new FormData()
      formData.append('file', file)

      // 设置上传状态
      this.uploading = true

      try {
        // 显示加载状态
        const loadingInstance = this.$loading({
          lock: true,
          text: '图片上传中...',
          spinner: 'el-icon-loading',
          background: 'rgba(0, 0, 0, 0.7)'
        })

        const res = await uploadFileApi(formData, 'moment')

        if (res.code === 200) {
          this.momentForm.images.push(res.data)
          this.fileList.push({
            name: file.name,
            url: res.data
          })
          this.$message.success('上传成功')
        } else {
          this.$message.error(res.msg || '上传失败')
        }

        // 关闭加载状态
        loadingInstance.close()
      } catch (error) {
        console.error('上传图片失败:', error)
        this.$message.error('上传失败，请检查网络连接')
      } finally {
        // 无论成功失败，都重置上传状态
        this.uploading = false
      }
    },

    // 移除图片
    handleRemoveImage(file, fileList) {
      const index = this.momentForm.images.indexOf(file.url)
      if (index !== -1) {
        this.momentForm.images.splice(index, 1)
      }
      this.fileList = fileList
    },

    // 预览上传的图片
    handlePreviewUploadImage(file) {
      this.previewUrl = file.url
      this.previewVisible = true
    },

    // 提交说说
    async submitMoment() {
      // 检查编辑器内容是否为空（HTML标签不算内容）
      const contentText = this.editor ? this.editor.getText().trim() : '';
      if (!contentText) {
        this.$message.warning('说说内容不能为空')
        return
      }

      // 确保表单中的content值已更新为编辑器的最新内容
      if (this.editor) {
        this.momentForm.content = this.editor.getHtml();

        // 再次确保所有编辑器中的图片都包含在提交数据中
        try {
          const imgElements = this.editor.getElemsByType('image')
          if (imgElements && imgElements.length > 0) {
            const editorImgUrls = imgElements.map(elem => elem.src).filter(Boolean)

            if (editorImgUrls.length > 0) {
              // 确保所有图片都在images数组中
              editorImgUrls.forEach(url => {
                if (!this.momentForm.images.includes(url)) {
                  this.momentForm.images.push(url)
                }
              })
            }
          }
        } catch (err) {
          console.error('处理编辑器图片失败:', err)
        }
      }

      this.submitting = true
      try {
        // 使用已更新的表单内容
        const submitData = {
          content: this.momentForm.content,
          images: this.momentForm.images.join(',')
        }

        const res = await addMoment(submitData)
        if (res.code === 200) {
          this.$message.success('发布成功')
          this.dialogVisible = false
          // 重新加载说说列表
          this.fetchMoments()

          // 重置表单数据
          this.resetForm()
        } else {
          this.$message.error(res.msg || '发布失败')
        }
      } catch (error) {
        console.error('发布说说失败:', error)
        this.$message.error('发布失败')
      } finally {
        this.submitting = false
      }
    },

    // ===== 新增功能：说说删除 =====
    // 删除评论
    async handleDeleteComment(commentId, momentId) {
      if (!this.userInfo) {
        this.$message.warning('请先登录');
        this.$router.push('/login');
        return;
      }

      try {
        await this.$confirm('确定要删除这条评论吗？', '提示', {
          confirmButtonText: '确定',
          cancelButtonText: '取消',
          type: 'warning'
        });

        const res = await deleteComment(commentId);
        if (res.code === 200) {
          this.$message.success('删除成功');

          // 重新加载评论
          await this.loadComments(momentId);

          // 更新评论数
          await this.getMomentCommentCount(momentId);
        } else {
          this.$message.error(res.msg || '删除失败');
        }
      } catch (error) {
        if (error !== 'cancel') {
          console.error('删除评论失败:', error);
          this.$message.error('删除失败，请稍后重试');
        }
      }
    },

    // ===== 新增功能：说说点赞 =====

    // 检查说说点赞状态
    async checkMomentLikeStatus(momentId) {
      try {
        const res = await checkMomentLikeStatus(momentId)
        if (res.code === 200) {
          // 更新点赞状态
          const moment = this.moments.find(m => m.id === momentId)
          if (moment) {
            this.$set(moment, 'isLiked', res.data)
          }
        }
      } catch (error) {
        console.error('获取点赞状态失败:', error)
      }
    },
    // 获取说说点赞数
    async getMomentLikeCount(momentId) {
      try {
        const res = await getMomentLikeCount(momentId)
        if (res.code === 200) {
          // 更新点赞数
          const moment = this.moments.find(m => m.id === momentId)
          if (moment) {
            this.$set(moment, 'likeCount', res.data)
          }
        }
      } catch (error) {
        console.error('获取点赞数失败:', error)
      }
    },
    // 获取说说评论数
    async getMomentCommentCount(momentId) {
      try {
        const res = await getMomentCommentCount(momentId)
        if (res.code === 200) {
          // 更新评论数
          const moment = this.moments.find(m => m.id === momentId)
          if (moment) {
            this.$set(moment, 'commentCount', res.data)
          }
        }
      } catch (error) {
        console.error('获取评论数失败:', error)
      }
    },

    // 在提交评论或回复后更新评论数
    async updateCommentCount(momentId) {
      await this.getMomentCommentCount(momentId)
    },

    // 处理说说点赞/取消点赞
    async handleLikeMoment(moment) {
      if (!this.userInfo) {
        this.$message.warning('请先登录')
        this.$router.push('/login')
        return
      }

      try {
        const res = await toggleMomentLike(moment.id)
        if (res.code === 200) {
          // 更新点赞状态
          this.$set(moment, 'isLiked', res.data)

          // 更新点赞数
          await this.getMomentLikeCount(moment.id)
        }
      } catch (error) {
        console.error('点赞操作失败:', error)
        this.$message.error('操作失败，请稍后重试')
      }
    },
    // ===== 新增功能：说说评论 =====

    // 显示评论区
    async showComments(momentId) {
      const moment = this.moments.find(m => m.id === momentId)
      if (!moment) return

      // 切换评论区域显示状态
      this.$set(moment, 'showComments', !moment.showComments)

      // 如果是显示评论，且还没有加载过评论，则加载评论
      if (moment.showComments && (!moment.comments || moment.comments.length === 0)) {
        await this.loadComments(momentId)
      }
    },
    // 加载评论 确保添加UI状态属性
    // 加载评论时处理为扁平化结构
    async loadComments(momentId, page = 1) {
      const moment = this.moments.find(m => m.id === momentId);
      if (!moment) return;

      moment.commentsLoading = true;
      moment.commentPage = page;

      try {
        const res = await getMomentComments(momentId, page, moment.commentPageSize);

        if (res.code === 200) {
          const commentsData = res.data;

          // 更新评论列表和总数
          this.$set(moment, 'comments', commentsData.records || []);
          this.$set(moment, 'commentTotal', commentsData.total || 0);

          // 处理评论数据，转换为QQ风格的层级结构
          this.processCommentsToFlat(moment);

          // 检查评论点赞状态
        }
      } catch (error) {
        console.error('获取评论列表失败:', error);
      } finally {
        moment.commentsLoading = false;
      }
    },

    // 提交评论 添加更新评论数
    async submitComment(moment) {
      if (!this.userInfo) {
        this.$message.warning('请先登录')
        this.$router.push('/login')
        return
      }

      if (!moment.commentContent.trim()) {
        this.$message.warning('评论内容不能为空')
        return
      }

      moment.commentSubmitting = true

      try {
        const commentData = {
          momentId: moment.id,
          content: moment.commentContent.trim()
        }

        const res = await addComment(commentData)

        if (res.code === 200) {
          this.$message.success('评论成功')
          moment.commentContent = '' // 清空评论内容

          // 重新加载评论
          await this.loadComments(moment.id)

          // 更新评论数
          await this.getMomentCommentCount(moment.id)
          // moment.commentCount = (moment.commentCount || 0) + 1
        } else {
          this.$message.error(res.msg || '评论失败')
        }
      } catch (error) {
        console.error('提交评论失败:', error)
        this.$message.error('评论失败')
      } finally {
        moment.commentSubmitting = false
      }
    },
    // 显示回复表单 - 修复
    showReplyForm(comment, momentId) {
      // 关闭其他可能打开的回复表单
      this.moments.forEach(m => {
        if (m.id !== momentId) {
          m.showCommentForm = false;
          m.comments.forEach(c => {
            c.showReplyForm = false;
            if (c.children) {
              c.children.forEach(r => {
                r.showReplyForm = false;
              });
            }
          });
        }
      });

      // 找到当前说说
      const moment = this.moments.find(m => m.id === momentId);
      if (!moment) return;

      // 设置当前评论的回复表单显示状态
      comment.showReplyForm = !comment.showReplyForm;

      // 如果显示回复表单，则设置回复信息
      if (comment.showReplyForm) {
        // 修改：设置正确的回复对象信息
        this.replyInfo = {
          momentId: momentId,
          parentId: comment.id, // 直接使用当前评论的ID作为父ID
          replyUserId: comment.userId, // 设置被回复用户ID
          replyUserName: comment.nickname // 设置被回复用户名称
        };
      } else {
        this.replyInfo = null;
      }
    },
    // 显示回复表单 添加更新评论数

    // 取消回复
    cancelReply(comment) {
      this.$set(comment, 'showReplyForm', false);
      this.$set(comment, 'replyContent', '');
    },

    // 提交回复
    async submitReply(comment, momentId) {
      if (!this.userInfo) {
        this.$message.warning('请先登录');
        this.$router.push('/login');
        return;
      }

      if (!comment.replyContent || !comment.replyContent.trim()) {
        this.$message.warning('回复内容不能为空');
        return;
      }

      comment.replySubmitting = true;

      try {
        // 构建回复数据 - 关键是正确设置parentId和replyUserId
        const replyData = {
          momentId: momentId,
          content: comment.replyContent.trim(),
          parentId: comment.id // 直接使用当前评论的ID作为parentId
          // parentId: comment.parentId || comment.id, // 使用父评论ID或当前评论ID
          //TODO 有replyUserId问题需要解决--2025.4.1已解决oh yeah
          // 移除replyUserId，让后端根据parentId查询并设置
          // replyUserId: comment.userId // 设置被回复用户ID为当前评论的用户ID
        };

        console.log('提交回复数据:', replyData);

        // 使用正确的API函数 - 注意这里使用replyComment而不是addComment
        const res = await replyComment(replyData);

        if (res.code === 200) {
          this.$message.success('回复成功');
          comment.replyContent = ''; // 清空回复内容
          comment.showReplyForm = false; // 隐藏回复表单

          // 重新加载评论
          await this.loadComments(momentId);

          // 更新评论数
          await this.getMomentCommentCount(momentId);
        } else {
          this.$message.error(res.msg || '回复失败');
        }
      } catch (error) {
        console.error('提交回复失败:', error);
        this.$message.error('回复失败，请稍后重试');
      } finally {
        comment.replySubmitting = false;
      }
    },

    // ===== 新增功能：评论点赞 =====
    // 处理评论点赞/取消点赞
    async handleLikeComment(comment, momentId) {
      if (!this.userInfo) {
        this.$message.warning('请先登录')
        this.$router.push('/login')
        return
      }

      try {
        const res = await toggleCommentLike(comment.id)
        if (res.code === 200) {
          // 更新点赞状态和点赞数
          this.$set(comment, 'isLiked', res.data.liked)
          this.$set(comment, 'likeCount', res.data.likeCount)
        }
      } catch (error) {
        console.error('评论点赞操作失败:', error)
        this.$message.error('操作失败，请稍后重试')
      }
    },
    // 检查评论点赞状态
    async checkCommentLikeStatus(commentId) {
      try {
        const res = await checkCommentLikeStatus(commentId)
        if (res.code === 200) {
          // 遍历所有说说的所有评论，找到对应的评论并更新点赞状态
          this.moments.forEach(moment => {
            if (moment.comments) {
              moment.comments.forEach(comment => {
                if (comment.id === commentId) {
                  this.$set(comment, 'isLiked', res.data)
                }

                // 检查回复中是否有匹配的评论ID
                if (comment.children) {
                  comment.children.forEach(reply => {
                    if (reply.id === commentId) {
                      this.$set(reply, 'isLiked', res.data)
                    }
                  })
                }
              })
            }
          })
        }
      } catch (error) {
        console.error('获取评论点赞状态失败:', error)
      }
    },
    // 获取说说详情
    async getMomentDetail(momentId) {
      try {
        const res = await getMomentDetail(momentId, 1, 10)
        if (res.code === 200) {
          const detailData = res.data
          const moment = this.moments.find(m => m.id === momentId)
          this.processCommentsToFlat(moment);
          if (moment) {
            // 更新说说详情
            this.$set(moment, 'content', detailData.moment.content)
            this.$set(moment, 'images', detailData.moment.images)
            this.$set(moment, 'createTime', detailData.moment.createTime)
            this.$set(moment, 'updateTime', detailData.moment.updateTime)

            // 更新点赞信息
            this.$set(moment, 'likeCount', detailData.likeCount)
            this.$set(moment, 'isLiked', detailData.isLiked)

            // 更新评论信息
            const commentsData = detailData.comments
            this.$set(moment, 'comments', commentsData.records || [])
            this.$set(moment, 'commentTotal', commentsData.total || 0)
            this.$set(moment, 'commentPage', commentsData.current || 1)

            // 为每个评论添加UI状态属性
            moment.comments.forEach(comment => {
              this.$set(comment, 'showReplyForm', false)
              this.$set(comment, 'replyContent', '')
              this.$set(comment, 'replySubmitting', false)
              this.$set(comment, 'replyParentId', comment.id)

              // 处理回复
              if (comment.children && comment.children.length > 0) {
                comment.children.forEach(reply => {
                  this.$set(reply, 'showReplyForm', false)
                  this.$set(reply, 'replyContent', '')
                  this.$set(reply, 'replySubmitting', false)
                  this.$set(reply, 'replyParentId', comment.id)
                })
              }
            })
          }
        }
      } catch (error) {
        console.error('获取说说详情失败:', error)
      }
    },

    /**
     * 编辑器创建完成时的回调
     */
    onEditorCreated(editor) {
      this.editor = Object.seal(editor) // 记录编辑器实例

      // 检测设备类型并设置编辑器高度和工具栏
      this.checkMobileDevice()

      // 初始化编辑器配置
      this.initEditorConfig()
    },

    /**
     * 调整编辑器高度适应移动端视口
     */
    adjustEditorHeight() {
      // 此方法已废弃，改用 checkMobileDevice 中的逻辑
    },

    /**
     * 检测是否为移动设备
     */
    checkMobileDevice() {
      // 检测屏幕宽度是否小于768px
      const isMobileNow = window.innerWidth <= 768
      if (isMobileNow !== this.isMobile) {
        this.isMobile = isMobileNow
      }

      // 根据设备类型设置编辑器高度
      this.editorHeight = this.isMobile ? 'calc(70vh - 250px)' : '320px'

      // 动态设置工具栏的 `excludeKeys`
      const excludeKeys = ['fullScreen']; // 始终移除全屏按钮
      if (this.isMobile) {
        excludeKeys.push('emotion'); // 移动端额外移除表情按钮
      }
      this.toolbarConfig.excludeKeys = excludeKeys;


      // 如果编辑器已存在，重新配置工具栏
      if (this.editor) {
        this.initEditorConfig()
      }
    },

    /**
     * 初始化编辑器配置
     */
    initEditorConfig() {
      // 表格配置
      this.editorConfig.MENU_CONF['insertTable'] = {
        minWidth: 200,
        maxWidth: 700
      }

      // 代码块配置
      this.editorConfig.MENU_CONF['codeBlock'] = {
        // 使用在data中已经定义的语言列表
        languages: this.editorConfig.codeSelectLang,

        // 语法高亮处理
        customPaste: (text, htmlStr) => {
          // 如果是从其他代码编辑器复制来的代码，尝试保留其格式
          const codeMatch = htmlStr.match(/<code[^>]*>([\s\S]*?)<\/code>/i);
          if (codeMatch) {
            return codeMatch[1];
          }
          return text;
        },

        onInsertedCode: (codeElem) => {
          // 添加语言标识属性，便于前端渲染时识别
          try {
            const language = codeElem.getAttribute('data-language') || codeElem.className.replace('language-', '') || 'plaintext';
            if (codeElem.parentElement) {
              codeElem.parentElement.setAttribute('data-language', language);

              // 触发代码高亮
              setTimeout(() => {
                try {
                  applyHighlighting('.w-e-text-container');
                } catch (err) {
                  console.error('编辑器代码高亮失败:', err);
                }
              }, 100);
            }
          } catch (error) {
            console.error('设置代码块语言标识失败:', error);
          }
        }
      }

      // 链接配置
      this.editorConfig.MENU_CONF['insertLink'] = {
        checkLink: (text, url) => {
          // 添加对url格式的简单检查
          if (!url.startsWith('http://') && !url.startsWith('https://')) {
            return '链接必须以 http:// 或 https:// 开头';
          }
          return true;
        }
      }
    },

    /**
     * 处理编辑器内容变化
     */
    handleEditorChange(editor) {
      // 获取HTML内容并更新到表单
      this.momentForm.content = editor.getHtml()

      // 提取编辑器中插入的所有图片地址
      try {
        const imgUrls = []
        const imgElements = editor.getElemsByType('image')

        if (imgElements && imgElements.length > 0) {
          imgElements.forEach(elem => {
            const src = elem.src
            if (src && !imgUrls.includes(src)) {
              imgUrls.push(src)
            }
          })
        }

        // 更新表单中的images数组，以便提交时包含编辑器中插入的所有图片
        if (imgUrls.length > 0) {
          // 合并现有图片和编辑器中的图片
          const allImages = [...new Set([...this.momentForm.images, ...imgUrls])]
          this.momentForm.images = allImages
        }
      } catch (err) {
        console.error('提取编辑器图片失败:', err)
      }
    },

    /**
     * 对话框打开时的处理
     */
    onDialogOpen() {
      // 确保在对话框完全打开后，编辑器能够正确初始化
      this.$nextTick(() => {
        // 如果编辑器不存在，会通过Editor组件的@onCreated回调自动创建
        console.log('对话框已打开，等待编辑器初始化')

        // 检测设备类型
        this.checkMobileDevice()

        // 确保编辑器配置是最新的
        if (this.editor) {
          // 重新应用配置
          this.initEditorConfig()
        }
      })
    },
    goToUserPage(userId) {
      if (userId) {
        this.$router.push({
          path: `/user/${userId}`
        });
      }
    }
  }
}
</script>

<style lang="scss" scoped>
.moments-container {
  min-height: calc(100vh - 70px);
}

.main-content {
  max-width: 800px;
  margin: 0 auto;
}

// 新增说说按钮样式
.add-moment-btn-container {
  display: flex;
  justify-content: center;
  margin-top: 16px;
  width: 100%;
  position: relative;
  z-index: 1;
}

.add-moment-btn {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 14px;
  width: 100%;
  max-width: 340px;
  background: linear-gradient(135deg, var(--primary, #409EFF) 0%, #4dabf7 100%);
  color: #fff;
  padding: 20px 32px;
  border-radius: 50px;
  cursor: pointer;
  transition: all 0.5s cubic-bezier(0.175, 0.885, 0.32, 1.275);
  font-weight: 700;
  position: relative;
  overflow: hidden;
  box-shadow: 0 10px 20px rgba(64, 158, 255, 0.25),
    0 6px 8px rgba(64, 158, 255, 0.15),
    inset 0 -3px 0 rgba(0, 0, 0, 0.15);
  text-align: center;
  font-size: 17px;
  letter-spacing: 0.8px;
  transform-origin: center;

  &:hover {
    transform: translateY(-5px) scale(1.02);
    box-shadow: 0 15px 30px rgba(64, 158, 255, 0.25),
      0 10px 10px rgba(64, 158, 255, 0.15),
      inset 0 -3px 0 rgba(0, 0, 0, 0.15);
    background: linear-gradient(135deg, var(--primary, #409EFF) 10%, #4dabf7 110%);
  }

  &:active {
    transform: translateY(-1px) scale(0.98);
    box-shadow: 0 5px 15px rgba(64, 158, 255, 0.2),
      inset 0 2px 4px rgba(0, 0, 0, 0.1);
    background: linear-gradient(135deg, var(--primary, #3a8fe5) 0%, #409EFF 100%);
  }

  i {
    font-size: 20px;
    transition: all 0.4s cubic-bezier(0.68, -0.55, 0.265, 1.55);
    filter: drop-shadow(0 2px 4px rgba(0, 0, 0, 0.2));
  }

  &:hover i {
    transform: rotate(-15deg) scale(1.2) translateX(-2px);
  }

  .btn-shine {
    position: absolute;
    top: 0;
    left: -150%;
    width: 100%;
    height: 100%;
    background: linear-gradient(90deg,
        rgba(255, 255, 255, 0) 0%,
        rgba(255, 255, 255, 0.3) 50%,
        rgba(255, 255, 255, 0) 100%);
    animation: shine 4s infinite ease-in-out;
    transform: skewX(-20deg);
  }

  @keyframes shine {
    0% {
      left: -150%;
    }

    40%,
    100% {
      left: 150%;
    }
  }
}

/* 暗黑模式适配 */
@media (prefers-color-scheme: dark) {
  .add-moment-btn {
    background: linear-gradient(135deg, var(--primary, #409EFF) 0%, #1890ff 100%);
    box-shadow: 0 4px 16px rgba(24, 144, 255, 0.4);
  }
}

/* 自定义暗黑模式类 */
.dark-mode {
  .add-moment-btn {
    background: linear-gradient(135deg, var(--primary, #409EFF) 0%, #1890ff 100%);
    box-shadow: 0 4px 16px rgba(24, 144, 255, 0.4);
  }
}

.moment-item {
  border-radius: $border-radius-sm * 3;
  padding: $spacing-lg;
  margin-bottom: $spacing-sm;
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.02);
  display: flex;
  gap: 16px;
  cursor: pointer;
  transition: all 0.3s ease;

  // 增加卡片效果
  background: var(--card-bg, #ffffff);
  border: 1px solid rgba(0, 0, 0, 0.05);
  box-shadow: 0 2px 10px rgba(0, 0, 0, 0.035),
    0 1px 3px rgba(0, 0, 0, 0.05);

  &:hover {
    transform: translateY(-2px);
    box-shadow: 0 5px 15px rgba(0, 0, 0, 0.08),
      0 3px 5px rgba(0, 0, 0, 0.04);
  }

  // 点击效果
  &:active {
    transform: translateY(0);
    box-shadow: 0 2px 5px rgba(0, 0, 0, 0.06),
      0 1px 2px rgba(0, 0, 0, 0.03);
  }

  @media screen and (max-width: 768px) {
    flex-direction: column;
    gap: 12px;
    padding: $spacing-md;
  }
}

/* 通用时间显示样式 */
.moment-time,
.comment-time,
.reply-time {
  display: inline-flex;
  align-items: center;
  color: #909399;
  font-size: 13px;
  padding: 2px 6px;
  border-radius: 12px;
  transition: all 0.3s ease;
  position: relative;
  cursor: pointer;
  /* 使用指针光标而不是文本光标 */

  i {
    margin-right: 6px;
    font-size: 14px;
  }

  .time-text {
    white-space: nowrap;
  }

  /* 鼠标悬停效果 - 黑色提示框 */
  &:hover {
    background-color: rgba(64, 158, 255, 0.1);
    color: #409EFF;

    &::after {
      content: attr(data-full-time);
      position: absolute;
      top: -30px;
      left: 50%;
      transform: translateX(-50%);
      background-color: rgba(0, 0, 0, 0.8);
      color: white;
      padding: 4px 8px;
      border-radius: 4px;
      font-size: 12px;
      white-space: nowrap;
      z-index: 10;
      box-shadow: 0 2px 8px rgba(0, 0, 0, 0.2);
    }
  }
}

/* 说说时间容器样式 */
.moment-time-container {
  display: flex;
  flex-direction: column;
  gap: 4px;

  &.updated {
    position: relative;

    &::before {
      content: '';
      position: absolute;
      left: 10px;
      top: 22px;
      height: calc(100% - 22px);
      width: 1px;
      background-color: #e0e0e0;
      z-index: 0;
    }
  }

  /* 更新时间特殊样式 */
  .update-time {
    color: #E6A23C;
    font-style: italic;

    i {
      animation: spin 2s infinite linear;
      animation-play-state: paused;
    }

    &:hover {
      background-color: rgba(230, 162, 60, 0.1);
      color: #E6A23C;

      i {
        animation-play-state: running;
      }
    }
  }
}

/* 评论时间样式 */
.comment-time,
.reply-time {
  margin-left: 8px;
  font-size: 12px;
  padding: 1px 4px;
}

/* 图标旋转动画 */
@keyframes spin {
  from {
    transform: rotate(0deg);
  }

  to {
    transform: rotate(360deg);
  }
}

/* 暗色模式适配 */
@media (prefers-color-scheme: dark) {
  .moment-time-container {
    &.updated::before {
      background-color: #4c4c4c;
    }
  }

  .moment-time,
  .comment-time,
  .reply-time {
    &:hover {
      background-color: rgba(100, 180, 255, 0.15);

      &::after {
        background-color: rgba(40, 40, 40, 0.9);
      }
    }

    &.update-time {
      color: #E6A23C;

      &:hover {
        background-color: rgba(230, 162, 60, 0.15);
      }
    }
  }
}

/* 自定义暗色模式类 */
.dark-mode {
  .moment-time-container {
    &.updated::before {
      background-color: #4c4c4c;
    }
  }

  .moment-time,
  .comment-time,
  .reply-time {
    &:hover {
      background-color: rgba(100, 180, 255, 0.15);

      &::after {
        background-color: rgba(40, 40, 40, 0.9);
      }
    }

    &.update-time {
      color: #E6A23C;

      &:hover {
        background-color: rgba(230, 162, 60, 0.15);
      }
    }
  }
}

.user-avatar {
  flex-shrink: 0;
  width: 46px;

  .avatar {
    width: 46px;
    height: 46px;
    border-radius: $border-radius-md;
    object-fit: cover;
  }

  @media screen and (max-width: 768px) {
    width: auto;
    display: flex;
    align-items: center;
    gap: 12px;

    .avatar {
      width: 40px;
      height: 40px;
    }
  }
}



.moment-main {
  flex: 1;
  min-width: 0;

  .time {
    font-size: 13px;
    color: var(--text-secondary);
    display: flex;
    align-items: center;
    gap: 4px;

    i {
      &.el-icon-time {
        color: rgb(78, 105, 160);
      }

      &.el-icon-refresh {
        color: #e6a23c;
      }
    }
  }

  @media screen and (max-width: 768px) {
    .moment-header {
      display: none;
    }
  }
}

.moment-header {
  margin-bottom: 12px;
  display: flex;
  align-items: center;
  gap: 10px;

  .name {
    font-weight: 600;
    font-size: 1.1em;
    margin-right: 10px;
  }

  .time {
    font-size: 13px;
    color: var(--text-secondary);
    display: flex;
    align-items: center;
    gap: 4px;

    i {
      &.el-icon-time {
        color: rgb(75, 128, 235);
      }

      &.el-icon-refresh {
        color: #e6a23c;
      }
    }
  }
}

.user-link {
  cursor: pointer;
  transition: all 0.3s ease;
}

.user-link:hover {
  text-decoration: underline;
  color: var(--primary, #409eff);
}

// 美化说说操作区域
.moment-actions {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  margin-top: 16px;
  padding-top: 12px;
  border-top: 1px solid rgba(0, 0, 0, 0.05);
  position: relative;

  &:before {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    width: 50px;
    height: 1px;
    background: linear-gradient(90deg, var(--primary, #409EFF), transparent);
  }

  .action-item {
    display: flex;
    align-items: center;
    margin-right: 16px;
    margin-bottom: 6px;
    padding: 8px 14px;
    border-radius: 30px;
    cursor: pointer;
    transition: all 0.3s cubic-bezier(0.25, 0.46, 0.45, 0.94);
    background: rgba(0, 0, 0, 0.01);
    border: 1px solid rgba(0, 0, 0, 0.03);

    &:hover {
      background-color: rgba(0, 0, 0, 0.03);
      transform: translateY(-2px);
      box-shadow: 0 3px 10px rgba(0, 0, 0, 0.05);
    }

    &:active {
      transform: translateY(0);
      box-shadow: inset 0 1px 3px rgba(0, 0, 0, 0.1);
    }

    i {
      font-size: 16px;
      color: #8a8a8a; // 默认颜色改为浅灰色
      margin-right: 6px;
      transition: all 0.3s ease;

      &.liked {
        color: #e74c3c;
        animation: heart-beat 0.5s cubic-bezier(0.175, 0.885, 0.32, 1.275);
        transform: scale(1.2);
      }
    }

    span {
      margin-left: 4px;
      font-size: 14px;
      color: #606266;
      font-weight: 500;
    }
  }

  /* 移动端优化 */
  @media screen and (max-width: 768px) {
    justify-content: space-around;
    padding: 15px 5px 5px;
    margin-top: 12px;

    &:before {
      width: 80px;
    }

    .action-item {
      margin: 0 5px 10px;
      padding: 8px 12px;
      flex: 1;
      min-width: 0;
      justify-content: center;

      i {
        font-size: 18px;
      }

      span {
        font-size: 12px;
      }
    }
  }
}

@keyframes heart-beat {
  0% {
    transform: scale(1);
  }

  15% {
    transform: scale(1.3);
  }

  30% {
    transform: scale(0.95);
  }

  45% {
    transform: scale(1.2);
  }

  75% {
    transform: scale(1);
  }
}

/* 评论区样式 */
.comments-section {
  margin-top: 16px;
  border-top: 1px solid #ebeef5;
  padding-top: 16px;
}

/* 评论线程 */
.comment-thread {
  margin-bottom: 16px;
  padding-bottom: 8px;
  border-bottom: 1px solid #f0f2f5;

  &:last-child {
    border-bottom: none;
  }
}

/* 主评论样式 */
.comment-item {
  margin-bottom: 20px;
}

.main-comment {
  display: flex;
  margin-bottom: 12px;
}

.comment-avatar img {
  width: 40px;
  height: 40px;
  border-radius: 50%;
  object-fit: cover;
}

.comment-content {
  flex: 1;
  margin-left: 12px;
}

.comment-header {
  margin-bottom: 4px;
  display: flex;
  align-items: center;
}

.comment-user {
  font-weight: 500;
  color: #333;
  margin-right: 8px;
}

.comment-time {
  color: #909399;
  font-size: 12px;
}

.comment-text {
  margin-bottom: 8px;
  word-break: break-word;
  line-height: 1.5;
}

/* 回复列表样式 */
.replies-list {
  margin-left: 56px;
  /* 与主评论头像对齐 */
  background: linear-gradient(145deg, #f5f7fa, #eef2f7);
  border-radius: 12px;
  padding: 12px 16px;
  box-shadow:
    inset 0 1px 0 rgba(255, 255, 255, 0.7),
    0 3px 10px rgba(0, 0, 0, 0.03);
  border: 1px solid rgba(0, 0, 0, 0.03);
  position: relative;
  transition: all 0.3s ease;

  /* 添加装饰性左边框 */
  &:before {
    content: '';
    position: absolute;
    left: -1px;
    top: 10px;
    bottom: 10px;
    width: 3px;
    background: linear-gradient(to bottom, var(--primary, #409EFF), rgba(64, 158, 255, 0.4));
    border-radius: 3px;
  }

  &:hover {
    box-shadow:
      inset 0 1px 0 rgba(255, 255, 255, 0.7),
      0 5px 15px rgba(0, 0, 0, 0.05);
  }
}

.reply-item {
  display: flex;
  margin-bottom: 12px;
}

.reply-item:last-child {
  margin-bottom: 0;
}

.reply-avatar img {
  width: 32px;
  height: 32px;
  border-radius: 50%;
  object-fit: cover;
}

.reply-content {
  flex: 1;
  margin-left: 10px;
}

.reply-header {
  margin-bottom: 4px;
  display: flex;
  align-items: center;
  flex-wrap: wrap;
}

.reply-user {
  font-weight: 500;
  color: #333;
}

.reply-to {
  margin-left: 4px;
  color: #606266;
}

.reply-to-name {
  color: #409EFF;
}

.reply-time {
  color: #909399;
  font-size: 12px;
  margin-left: 8px;
}

.reply-text {
  margin-bottom: 6px;
  word-break: break-word;
  line-height: 1.5;
}

/* 操作按钮样式 */
.comment-actions,
.reply-actions {
  display: flex;
  align-items: center;
}

/* 头像样式统一 */
.comment-avatar img,
.reply-avatar img {
  border-radius: 50%;
  object-fit: cover;
}

.comment-avatar img {
  width: 40px;
  height: 40px;
}

.reply-avatar img {
  width: 36px;
  height: 36px;
  box-shadow: 0 2px 6px rgba(0, 0, 0, 0.1);
  border: 2px solid #fff;
  transition: all 0.3s ease;

  &:hover {
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
    transform: scale(1.08);
  }
}

/* 评论和回复共用样式 */
.comment-item,
.reply-item {
  display: flex;
  margin-bottom: 15px;
  animation: fadeIn 0.3s ease-out;
  transition: all 0.25s ease;

  &:hover {
    transform: translateY(-2px);
  }
}

.comment-content,
.reply-content {
  flex: 1;
  margin-left: 12px;
}

.comment-header,
.reply-header {
  margin-bottom: 4px;
  display: flex;
  align-items: center;
  flex-wrap: wrap;
}

.comment-user,
.reply-user {
  font-weight: 600;
  color: #2c3e50;
  margin-right: 8px;
  position: relative;

  &:after {
    content: '';
    position: absolute;
    left: 0;
    bottom: -1px;
    width: 0;
    height: 1px;
    background: linear-gradient(90deg, var(--primary, #409EFF), transparent);
    transition: width 0.3s ease;
  }

  &:hover:after {
    width: 100%;
  }
}

.comment-time,
.reply-time {
  color: #909399;
  font-size: 12px;
  margin-left: auto;
}

.comment-text,
.reply-text {
  margin-bottom: 8px;
  word-break: break-word;
  line-height: 1.6;
  font-size: 14px;
  color: #303133;
  padding: 2px 0;
  transition: color 0.2s ease;

  &:hover {
    color: #000;
  }
}

/* 回复样式 */
.replies-list {
  margin-left: 52px;
  /* 与主评论头像对齐 */
  background-color: #f5f7fa;
  border-radius: 8px;
  padding: 8px;
}

.reply-to {
  color: #606266;
  font-size: 13px;
  margin-right: 8px;
  font-style: italic;

  &:before {
    content: '→';
    margin-right: 3px;
    font-weight: bold;
  }
}

.reply-to-name {
  color: #409EFF;
  font-weight: 500;
  position: relative;

  &:after {
    content: '';
    position: absolute;
    left: 0;
    bottom: -1px;
    width: 0;
    height: 1px;
    background-color: #409EFF;
    transition: width 0.3s ease;
  }

  &:hover:after {
    width: 100%;
  }
}

/* 操作按钮统一样式 */
.comment-actions,
.reply-actions {
  display: flex;
  align-items: center;
}

.action-btn {
  display: flex;
  align-items: center;
  margin-right: 16px;
  padding: 5px 12px;
  border-radius: 20px;
  cursor: pointer;
  transition: all 0.3s cubic-bezier(0.25, 0.46, 0.45, 0.94);
  font-size: 13px;
  background-color: rgba(0, 0, 0, 0.01);
  border: 1px solid rgba(0, 0, 0, 0.03);
  position: relative;
  overflow: hidden;

  &:before {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: radial-gradient(circle at center, rgba(255, 255, 255, 0.2) 0%, transparent 70%);
    opacity: 0;
    transition: opacity 0.3s ease;
  }

  &:hover {
    background-color: rgba(0, 0, 0, 0.03);
    transform: translateY(-2px);
    box-shadow: 0 3px 10px rgba(0, 0, 0, 0.06);
    border-color: rgba(0, 0, 0, 0.05);

    &:before {
      opacity: 1;
    }
  }

  &:active {
    transform: translateY(0);
    box-shadow: inset 0 1px 3px rgba(0, 0, 0, 0.1);
  }

  i {
    font-size: 14px;
    margin-right: 6px;
    transition: all 0.3s ease;

    &.liked {
      color: #e74c3c;
      animation: heartBeat 0.6s cubic-bezier(0.215, 0.61, 0.355, 1);
    }
  }

  &:hover i {
    transform: scale(1.15);
  }

  span {
    color: #606266;
    font-weight: 500;
    transition: color 0.3s ease;
  }

  &:hover span {
    color: #303133;
  }
}

@keyframes heartBeat {
  0% {
    transform: scale(1);
  }

  14% {
    transform: scale(1.3);
  }

  28% {
    transform: scale(1);
  }

  42% {
    transform: scale(1.2);
  }

  70% {
    transform: scale(1);
  }
}

.delete-btn {
  cursor: pointer;
  color: #909399;
  font-size: 14px;
  margin-left: 8px;
  opacity: 0;
  transition: all 0.3s;

  &:hover {
    color: #f56c6c;
  }
}

.comment-item:hover .delete-btn,
.reply-item:hover .delete-btn {
  opacity: 1;
}

/* 表单样式统一 */
.reply-form,
.comment-form {
  margin-top: 10px;
  margin-bottom: 10px;
}

.reply-form {
  padding: 16px;
  background: linear-gradient(145deg, #f9fbfd, #f0f4f8);
  border-radius: 12px;
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.04),
    inset 0 1px 0 rgba(255, 255, 255, 0.7);
  animation: fadeIn 0.4s cubic-bezier(0.19, 1, 0.22, 1);
  border: 1px solid rgba(0, 0, 0, 0.03);
  margin-top: 12px;
  transform-origin: top center;
}

.reply-input,
.comment-input {
  margin-bottom: 12px;

  .el-textarea__inner {
    padding: 14px;
    min-height: 80px;
    font-size: 15px;
    border-radius: 12px;
    resize: none;
    transition: all 0.3s ease;
    border-color: #e0e0e0;
    box-shadow: inset 0 1px 3px rgba(0, 0, 0, 0.02);

    &::placeholder {
      color: #aaa;
      font-style: italic;
      opacity: 0.7;
    }

    &:hover {
      border-color: #c0c4cc;
    }

    &:focus {
      border-color: var(--primary, #409EFF);
      box-shadow: 0 0 0 3px rgba(64, 158, 255, 0.1);
    }
  }
}

.form-actions {
  display: flex;
  justify-content: flex-end;
  gap: 12px;

  .el-button {
    padding: 10px 24px;
    border-radius: 30px;
    font-size: 14px;
    font-weight: 600;
    letter-spacing: 0.3px;
    box-shadow: 0 2px 6px rgba(0, 0, 0, 0.05),
      inset 0 -2px 0 rgba(0, 0, 0, 0.1);
    transition: all 0.3s cubic-bezier(0.25, 0.46, 0.45, 0.94);

    &:hover {
      transform: translateY(-2px);
      box-shadow: 0 4px 12px rgba(0, 0, 0, 0.1),
        inset 0 -2px 0 rgba(0, 0, 0, 0.12);
    }

    &:active {
      transform: translateY(0);
      box-shadow: 0 2px 4px rgba(0, 0, 0, 0.05),
        inset 0 2px 4px rgba(0, 0, 0, 0.1);
    }

    &.is-loading {
      padding-left: 24px;
    }

    &.el-button--primary {
      background: linear-gradient(135deg, var(--primary, #409EFF) 0%, #4dabf7 100%);
      border-color: transparent;

      &:hover {
        background: linear-gradient(135deg, var(--primary, #409EFF) 10%, #4dabf7 110%);
      }
    }
  }
}

/* 无评论提示 */
.no-comments {
  text-align: center;
  padding: 20px 0;
  color: #909399;
  font-size: 14px;

  i {
    font-size: 20px;
    margin-right: 8px;
    vertical-align: middle;
  }
}

/* 评论分页 */
.comments-pagination {
  margin-top: 16px;
  text-align: center;
}

/* 动画效果 */
@keyframes fadeIn {
  from {
    opacity: 0;
    transform: translateY(10px);
  }

  to {
    opacity: 1;
    transform: translateY(0);
  }
}

/* 点赞动画 */
.liked {
  animation: likeAnimation 0.4s cubic-bezier(0.17, 0.89, 0.32, 1.49);
}

@keyframes likeAnimation {
  0% {
    transform: scale(1);
  }

  50% {
    transform: scale(1.4);
  }

  100% {
    transform: scale(1.1);
  }
}

.comment-action,
.reply-action {
  display: flex;
  align-items: center;
  margin-right: 16px;
  padding: 2px 8px;
  border-radius: 12px;
  cursor: pointer;
  transition: all 0.2s ease;
  font-size: 12px;
}

.comment-action:hover,
.reply-action:hover {
  background-color: rgba(0, 0, 0, 0.05);
}

.comment-action i,
.reply-action i {
  font-size: 14px;
  margin-right: 4px;
}

.comment-action i.liked,
.reply-action i.liked {
  color: #e74c3c;
}

.comment-action span,
.reply-action span {
  color: #606266;
}

/* 回复表单样式 */
.reply-form {
  margin-top: 10px;
  margin-bottom: 10px;
  padding: 12px;
  background-color: #f5f7fa;
  border-radius: 8px;
  box-shadow: 0 2px 4px rgba(0, 0, 0, 0.05);
}

.reply-form .reply-input {
  margin-bottom: 10px;
}

.reply-form .reply-form-actions {
  display: flex;
  justify-content: flex-end;
  gap: 10px;
}

/* 无评论提示 */
.no-comments {
  text-align: center;
  padding: 20px 0;
  color: #909399;
  font-size: 14px;

  i {
    font-size: 20px;
    margin-right: 8px;
    vertical-align: middle;
  }
}

/* 评论表单 */
.comment-form {
  margin-top: 16px;

  .comment-input {
    margin-bottom: 12px;
  }

  .comment-form-actions {
    display: flex;
    justify-content: flex-end;
  }
}

/* 评论分页 */
.comments-pagination {
  margin-top: 16px;
  text-align: center;
}

// 美化评论区域
.comments-section {
  margin-top: 24px;
  background-color: #f9f9f9;
  background-image: linear-gradient(to bottom, #f0f4f8, #f9f9f9);
  border-radius: 18px;
  padding: 24px;
  box-shadow:
    inset 0 1px 0 rgba(255, 255, 255, 0.8),
    inset 0 0 10px rgba(0, 0, 0, 0.03),
    0 4px 8px rgba(0, 0, 0, 0.04);
  transition: all 0.4s cubic-bezier(0.165, 0.84, 0.44, 1);
  border: 1px solid rgba(0, 0, 0, 0.03);
  position: relative;
  overflow: hidden;

  &:after {
    content: '';
    position: absolute;
    top: 0;
    right: 0;
    width: 100px;
    height: 100px;
    background: radial-gradient(circle at top right, rgba(64, 158, 255, 0.08), transparent 70%);
    pointer-events: none;
  }

  &:hover {
    box-shadow:
      inset 0 1px 0 rgba(255, 255, 255, 0.8),
      inset 0 0 10px rgba(0, 0, 0, 0.04),
      0 8px 16px rgba(0, 0, 0, 0.06);
    transform: translateY(-2px);
  }

  .comments-loading {
    padding: 16px 0;
  }

  .comments-list {
    .comment-item {
      display: flex;
      margin-bottom: 16px;
      position: relative;

      &:last-child {
        margin-bottom: 0;
      }

      &:after {
        content: '';
        position: absolute;
        bottom: -8px;
        left: 48px;
        right: 0;
        height: 1px;
        background: linear-gradient(to right, rgba(0, 0, 0, 0.05), transparent);
      }

      &:last-child:after {
        display: none;
      }

      .comment-avatar {
        width: 36px;
        height: 36px;
        margin-right: 12px;
        flex-shrink: 0;

        img {
          width: 100%;
          height: 100%;
          border-radius: 50%;
          object-fit: cover;
          box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1);
          border: 2px solid #fff;
        }
      }

      .comment-content {
        flex: 1;
        min-width: 0;

        .comment-header {
          display: flex;
          align-items: center;
          flex-wrap: wrap;
          margin-bottom: 4px;

          .comment-user {
            font-weight: 600;
            font-size: 14px;
            color: #333;
            margin-right: 8px;
          }

          .comment-time {
            font-size: 12px;
            color: #909399;
          }
        }

        .comment-text {
          font-size: 14px;
          line-height: 1.5;
          color: #333;
          word-break: break-word;
          margin-bottom: 8px;
        }

        .comment-actions {
          display: flex;
          align-items: center;

          .comment-action {
            display: flex;
            align-items: center;
            margin-right: 16px;
            padding: 2px 8px;
            border-radius: 12px;
            cursor: pointer;
            transition: all 0.2s ease;
            font-size: 12px;

            &:hover {
              background-color: rgba(0, 0, 0, 0.05);
            }

            i {
              font-size: 14px;
              margin-right: 4px;

              &.liked {
                color: #e74c3c;
              }
            }

            span {
              color: #606266;
            }
          }
        }

        // 回复列表样式
        .replies-list {
          margin-top: 12px;
          margin-left: 8px;
          padding-left: 12px;
          border-left: 2px solid rgba(0, 0, 0, 0.05);

          .reply-item {
            display: flex;
            margin-bottom: 12px;

            &:last-child {
              margin-bottom: 0;
            }

            .reply-avatar {
              width: 28px;
              height: 28px;
              margin-right: 10px;
              flex-shrink: 0;

              img {
                width: 100%;
                height: 100%;
                border-radius: 50%;
                object-fit: cover;
                box-shadow: 0 1px 3px rgba(0, 0, 0, 0.1);
                border: 1px solid #fff;
              }
            }

            .reply-content {
              flex: 1;
              min-width: 0;

              .reply-header {
                display: flex;
                align-items: center;
                flex-wrap: wrap;
                margin-bottom: 3px;

                .reply-user {
                  font-weight: 600;
                  font-size: 13px;
                  color: #333;
                  margin-right: 4px;
                }

                .reply-to {
                  font-size: 12px;
                  color: #606266;
                  margin-right: 4px;

                  &:before {
                    content: '→';
                    margin-right: 2px;
                  }
                }

                .reply-time {
                  font-size: 12px;
                  color: #909399;
                }
              }

              .reply-text {
                font-size: 13px;
                line-height: 1.5;
                color: #333;
                word-break: break-word;
                margin-bottom: 6px;
              }

              .reply-actions {
                display: flex;
                align-items: center;

                .reply-action {
                  display: flex;
                  align-items: center;
                  margin-right: 12px;
                  padding: 1px 6px;
                  border-radius: 10px;
                  cursor: pointer;
                  transition: all 0.2s ease;
                  font-size: 12px;

                  &:hover {
                    background-color: rgba(0, 0, 0, 0.05);
                  }

                  i {
                    font-size: 12px;
                    margin-right: 3px;

                    &.liked {
                      color: #e74c3c;
                    }
                  }

                  span {
                    color: #606266;
                  }
                }
              }
            }
          }
        }

        // 回复表单样式
        .reply-form {
          margin-top: 12px;
          background-color: #fff;
          border-radius: 8px;
          padding: 12px;
          box-shadow: 0 2px 8px rgba(0, 0, 0, 0.05);

          .reply-input {
            margin-bottom: 8px;

            .el-textarea__inner {
              padding: 8px 12px;
              min-height: 60px;
              font-size: 14px;
              border-radius: 8px;
              resize: none;

              &:focus {
                border-color: var(--primary-color);
              }
            }
          }

          .reply-form-actions {
            display: flex;
            justify-content: flex-end;
            gap: 8px;

            .el-button {
              padding: 6px 12px;
              font-size: 13px;
              border-radius: 6px;
            }
          }
        }
      }
    }
  }

  /* 评论项样式 */
  .comment-item {
    display: flex;
    margin-bottom: 20px;
    position: relative;
    transition: transform 0.2s ease, box-shadow 0.3s ease;
    padding: 12px;
    border-radius: 12px;

    &:hover {
      background-color: rgba(0, 0, 0, 0.01);
      box-shadow: 0 2px 10px rgba(0, 0, 0, 0.02);
      transform: translateY(-2px);
    }
  }

  /* 评论头像 */
  .comment-avatar {
    flex-shrink: 0;
    margin-right: 14px;
    position: relative;

    &::after {
      content: '';
      position: absolute;
      width: 8px;
      height: 8px;
      background-color: #52c41a;
      border-radius: 50%;
      bottom: 0;
      right: 0;
      border: 2px solid #fff;
      box-shadow: 0 0 0 1px rgba(0, 0, 0, 0.05);
      opacity: 0;
      transform: scale(0);
      transition: all 0.3s ease;
    }

    img {
      width: 42px;
      height: 42px;
      border-radius: 50%;
      object-fit: cover;
      box-shadow: 0 2px 6px rgba(0, 0, 0, 0.08);
      border: 2px solid #fff;
      transition: all 0.3s ease;
    }

    &:hover {
      &::after {
        opacity: 1;
        transform: scale(1);
      }

      img {
        box-shadow: 0 4px 10px rgba(0, 0, 0, 0.15);
        transform: scale(1.05);
      }
    }
  }

  /* 评论内容区 */
  .comment-content {
    flex-grow: 1;
    overflow: hidden;
  }

  /* 评论头部 */
  .comment-header {
    margin-bottom: 6px;
    display: flex;
    align-items: center;
    flex-wrap: wrap;

    .comment-user {
      font-weight: 600;
      color: #2c3e50;
      margin-right: 6px;
      position: relative;

      &:after {
        content: '';
        position: absolute;
        left: 0;
        bottom: -2px;
        width: 0;
        height: 1px;
        background: linear-gradient(90deg, var(--primary, #409EFF), transparent);
        transition: width 0.3s ease;
      }

      &:hover:after {
        width: 100%;
      }
    }

    .reply-to {
      color: #606266;
      margin-right: 8px;
      font-style: italic;

      .reply-to-name {
        color: #409EFF;
        font-weight: 500;
        position: relative;

        &:after {
          content: '';
          position: absolute;
          left: 0;
          bottom: -1px;
          width: 0;
          height: 1px;
          background-color: #409EFF;
          transition: width 0.3s ease;
        }

        &:hover:after {
          width: 100%;
        }
      }
    }

    .comment-time {
      color: #909399;
      font-size: 12px;
      transition: color 0.2s ease;

      &:hover {
        color: #606266;
      }
    }
  }

  /* 评论文本 */
  .comment-text {
    margin-bottom: 10px;
    word-break: break-word;
    line-height: 1.6;
    font-size: 15px;
    color: #303133;
    padding: 2px 0;
    transition: color 0.2s ease;

    &:hover {
      color: #000;
    }
  }

  /* 评论操作区 */
  .comment-actions {
    display: flex;
    align-items: center;

    .comment-action {
      display: flex;
      align-items: center;
      margin-right: 16px;
      padding: 2px 8px;
      border-radius: 12px;
      cursor: pointer;
      transition: all 0.2s ease;
      font-size: 12px;

      &:hover {
        background-color: rgba(0, 0, 0, 0.05);
      }

      i {
        font-size: 14px;
        margin-right: 4px;

        &.liked {
          color: #e74c3c;
        }
      }

      span {
        color: #606266;
      }
    }
  }

  /* 回复表单 */
  .reply-form {
    margin-top: 12px;
    margin-bottom: 12px;
    padding: 12px;
    background-color: #f5f7fa;
    border-radius: 8px;
    box-shadow: 0 2px 4px rgba(0, 0, 0, 0.05);

    .reply-input {
      margin-bottom: 10px;
    }

    .reply-form-actions {
      display: flex;
      justify-content: flex-end;
      gap: 10px;
    }
  }

  /* 评论分隔线 */
  .comment-divider {
    position: absolute;
    bottom: -8px;
    left: 48px;
    right: 0;
    height: 1px;
    background-color: #ebeef5;
  }

  // 评论分页
  .comments-pagination {
    display: flex;
    justify-content: center;
    margin-top: 16px;

    .el-pagination {
      padding: 0;

      .btn-prev,
      .btn-next {
        background-color: #fff;
        border-radius: 4px;
      }

      .el-pager li {
        background-color: #fff;
        border-radius: 4px;

        &.active {
          background-color: var(--primary-color);
          color: #fff;
        }
      }
    }
  }

  // 无评论提示
  .no-comments {
    text-align: center;
    color: #909399;
    padding: 24px 0;
    font-size: 14px;

    i {
      font-size: 24px;
      margin-bottom: 8px;
      display: block;
    }
  }

  // 评论表单
  .comment-form {
    margin-top: 20px;
    background-color: #fff;
    border-radius: 10px;
    padding: 16px;
    box-shadow: 0 2px 12px rgba(0, 0, 0, 0.05);

    .comment-input {
      margin-bottom: 12px;

      .el-textarea__inner {
        padding: 12px;
        min-height: 80px;
        font-size: 14px;
        border-radius: 8px;
        resize: none;
        transition: all 0.3s ease;

        &:focus {
          border-color: var(--primary-color);
          box-shadow: 0 0 0 2px rgba(var(--primary-color-rgb), 0.1);
        }
      }
    }

    .comment-form-actions {
      display: flex;
      justify-content: flex-end;

      .el-button {
        padding: 8px 20px;
        border-radius: 20px;
        font-size: 14px;
        font-weight: 500;

        &.is-loading {
          padding-left: 20px;
        }
      }
    }
  }
}

// 动画效果
.comment-item,
.reply-item {
  animation: fadeIn 0.3s ease-out;
}

@keyframes fadeIn {
  from {
    opacity: 0;
    transform: translateY(10px);
  }

  to {
    opacity: 1;
    transform: translateY(0);
  }
}

// 点赞动画
.liked {
  animation: likeAnimation 0.4s cubic-bezier(0.17, 0.89, 0.32, 1.49);
}

@keyframes likeAnimation {
  0% {
    transform: scale(1);
  }

  50% {
    transform: scale(1.4);
  }

  100% {
    transform: scale(1.1);
  }
}

// 移动端适配优化
@media screen and (max-width: 768px) {
  .comments-section {
    padding: 12px;

    .comment-item {
      .comment-avatar {
        width: 32px;
        height: 32px;
      }

      .comment-content {
        .replies-list {
          margin-left: 0;
          padding-left: 8px;

          .reply-item {
            .reply-avatar {
              width: 24px;
              height: 24px;
            }
          }
        }
      }
    }

    .comment-form {
      padding: 12px;
    }
  }
}

.moment-content-wrapper {
  background: var(--card-bg);
  padding: 20px;
  border-radius: 0 $border-radius-lg*2 $border-radius-lg*2 $border-radius-lg*2;
  box-shadow: 0 2px 12px rgba(0, 0, 0, 0.03);
  transition: all 0.4s cubic-bezier(0.165, 0.84, 0.44, 1);
  position: relative;
  overflow: hidden;

  &:before {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    width: 4px;
    height: 100%;
    background: linear-gradient(to bottom, var(--primary, #409EFF), #64b5ff);
    opacity: 0;
    transition: opacity 0.3s ease;
  }

  &:hover {
    box-shadow: 0 6px 20px rgba(0, 0, 0, 0.08);
    transform: translateY(-2px);

    &:before {
      opacity: 1;
    }
  }

  @media screen and (max-width: 768px) {
    border-radius: $border-radius-lg;
    padding: 16px;
  }

  .moment-content {
    color: var(--text-primary);
    line-height: 1.85;
    font-size: 16px;
    white-space: pre-wrap;
    word-break: break-word;
    letter-spacing: 0.2px;

    // 添加收缩内容的样式
    transition: max-height 0.4s cubic-bezier(0.165, 0.84, 0.44, 1);

    &.collapsed {
      max-height: 300px;
      overflow: hidden;
      position: relative;

      &::after {
        content: '';
        position: absolute;
        bottom: 0;
        left: 0;
        width: 100%;
        height: 80px;
        background: linear-gradient(to bottom, rgba(255, 255, 255, 0), rgba(255, 255, 255, 1));
        pointer-events: none;
        backdrop-filter: blur(0.5px);
      }
    }

    &.expanding {
      animation: expandContent 0.6s cubic-bezier(0.19, 1, 0.22, 1) forwards;
    }

    @keyframes expandContent {
      from {
        max-height: 300px;
      }

      to {
        max-height: 2000px;
      }
    }

    // 添加微妙的渐变内容效果
    &.collapsed::after {
      transition: opacity 0.4s ease;
    }

    /* 暗黑模式下的渐变遮罩 */
    @media (prefers-color-scheme: dark) {
      &.collapsed::after {
        background: linear-gradient(to bottom, rgba(31, 32, 34, 0), rgba(31, 32, 34, 1));
      }
    }

    /* 自定义暗黑模式类 */
    .dark-mode & {
      &.collapsed::after {
        background: linear-gradient(to bottom, rgba(31, 32, 34, 0), rgba(31, 32, 34, 1));
      }
    }

    // 富文本内容样式
    :deep(p) {
      margin-bottom: 10px;
      line-height: 1.8;
    }

    :deep(h1, h2, h3, h4, h5, h6) {
      margin: 16px 0 10px;
      font-weight: 600;
      line-height: 1.4;
      color: var(--text-primary);
    }

    :deep(h1) {
      font-size: 24px;
    }

    :deep(h2) {
      font-size: 22px;
    }

    :deep(h3) {
      font-size: 20px;
    }

    :deep(h4) {
      font-size: 18px;
    }

    :deep(h5) {
      font-size: 16px;
    }

    :deep(h6) {
      font-size: 15px;
    }

    :deep(a) {
      color: var(--primary, #409EFF);
      text-decoration: none;
      border-bottom: 1px solid transparent;
      transition: border-color 0.3s;

      &:hover {
        border-bottom-color: var(--primary, #409EFF);
      }
    }

    :deep(code) {
      background-color: rgba(0, 0, 0, 0.05);
      padding: 2px 4px;
      border-radius: 3px;
      font-family: Consolas, Monaco, 'Andale Mono', monospace;
      font-size: 14px;
    }

    /* 代码高亮样式通过导入highlight.css处理，这里只添加特定的覆盖样式 */
    :deep(pre) {
      margin: 16px 0;
      position: relative;

      /* 针对移动设备的特殊处理 */
      @media screen and (max-width: 768px) {
        font-size: 13px;
        padding: 12px;
      }

      /* 确保代码复制按钮在悬停时显示 */
      &:hover .code-copy-btn {
        opacity: 0.8;
      }

      /* 添加滚动条美化 */
      &::-webkit-scrollbar {
        height: 6px;
        width: 6px;
      }

      &::-webkit-scrollbar-thumb {
        background: rgba(255, 255, 255, 0.2);
        border-radius: 3px;
      }

      &::-webkit-scrollbar-track {
        background: rgba(0, 0, 0, 0.1);
      }
    }

    :deep(blockquote) {
      border-left: 4px solid var(--primary, #409EFF);
      padding: 10px 15px;
      margin: 10px 0;
      background-color: rgba(0, 0, 0, 0.03);
      color: #666;
      font-style: italic;
    }

    :deep(ul, ol) {
      padding-left: 20px;
      margin: 10px 0;
    }

    :deep(li) {
      margin-left: 30px;
      margin-bottom: 5px;
    }

    :deep(img) {
      max-width: 100%;
      height: auto;
      border-radius: 5px;
    }

    :deep(table) {
      border-collapse: collapse;
      width: 100%;
      margin: 10px 0;

      th,
      td {
        border: 1px solid #ddd;
        padding: 8px;
      }

      th {
        background-color: #f5f5f5;
        font-weight: 600;
        text-align: left;
      }

      tr:nth-child(even) {
        background-color: #f9f9f9;
      }
    }

    /* 暗黑模式适配 */
    @media (prefers-color-scheme: dark) {
      :deep(code) {
        background-color: rgba(255, 255, 255, 0.1);
      }

      :deep(pre) {
        background-color: #1e2127;
        box-shadow: 0 3px 6px rgba(0, 0, 0, 0.2);

        code {
          color: #dcdfe6;
        }

        &::before {
          background-color: rgba(0, 0, 0, 0.4);
        }
      }

      :deep(blockquote) {
        background-color: rgba(255, 255, 255, 0.05);
        color: #bbb;
        border-left-color: #1890ff;
      }

      :deep(table) {
        th {
          background-color: #2c2d30;
        }

        th,
        td {
          border-color: #3e4045;
        }

        tr:nth-child(even) {
          background-color: #2a2b2e;
        }
      }

      :deep(a) {
        color: #1890ff;
      }

      :deep(img) {
        box-shadow: 0 2px 8px rgba(0, 0, 0, 0.3);
      }
    }
  }

  // 修改图片网格样式
  .moment-images {
    display: grid;
    grid-template-columns: repeat(3, 1fr); // 固定为3列
    gap: 8px;
    margin-top: 10px;
    margin-bottom: 10px;

    @media screen and (max-width: 768px) {
      grid-template-columns: repeat(2, 1fr); // 移动端2列
    }

    // 图片容器
    .image-container {
      position: relative;
      width: 100%;
      padding-top: 100%; // 1:1 比例
      overflow: hidden;
      border-radius: 10px;
      background-color: #f5f5f5;
      cursor: zoom-in;
      box-shadow: 0 2px 8px rgba(0, 0, 0, 0.04);
      transition: all 0.4s cubic-bezier(0.165, 0.84, 0.44, 1);

      &:after {
        content: '';
        position: absolute;
        top: 0;
        left: 0;
        right: 0;
        bottom: 0;
        border-radius: 10px;
        box-shadow: inset 0 0 0 1px rgba(0, 0, 0, 0.05);
        pointer-events: none;
        z-index: 1;
      }

      &:hover {
        transform: translateY(-3px);
        box-shadow: 0 8px 16px rgba(0, 0, 0, 0.1);
      }

      img {
        position: absolute;
        top: 0;
        left: 0;
        width: 100%;
        height: 100%;
        object-fit: cover; // 保持比例填充
        transition: transform 0.5s cubic-bezier(0.165, 0.84, 0.44, 1);

        &:hover {
          transform: scale(1.08);
        }

        &.lazy-load-error {
          object-fit: contain;
          padding: 12px;
        }
      }
    }
  }
}

.mobile-user-info {
  display: none;
  flex-direction: column;

  @media screen and (max-width: 768px) {
    display: flex;
  }

  .name {
    font-size: 15px;
    font-weight: 500;
    color: var(--text-primary);
  }

  .time {
    font-size: 13px;
    color: var(--text-secondary);
    display: flex;
    align-items: center;
    gap: 4px;
    margin-top: 2px;

    i {
      color: $primary;
    }
  }
}

// 上传图片组件样式
.upload-images {
  :deep(.el-upload--picture-card) {
    width: 100px;
    height: 100px;
    line-height: normal;
    border-radius: 8px;
    border: 1px dashed #d9d9d9;
    background-color: #fafafa;
    transition: all 0.3s ease;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;

    &:hover {
      border-color: var(--primary);
      color: var(--primary);
      transform: translateY(-2px);
      box-shadow: 0 4px 10px rgba(0, 0, 0, 0.05);
    }

    // 添加图片文本
    .upload-text {
      margin-top: 6px;
      font-size: 12px;
      color: #909399;
      line-height: 1;
    }

    i {
      font-size: 24px;
    }
  }

  // 上传中样式
  &.is-uploading {
    :deep(.el-upload--picture-card) {
      border-color: var(--primary);
      background-color: rgba(64, 158, 255, 0.05);
      position: relative;
      overflow: hidden;

      &:before {
        content: '';
        position: absolute;
        bottom: 0;
        left: 0;
        height: 2px;
        width: 100%;
        background: linear-gradient(90deg,
            transparent 0%,
            var(--primary) 50%,
            transparent 100%);
        animation: uploading-progress 1.5s infinite ease-in-out;
      }

      @keyframes uploading-progress {
        0% {
          transform: translateX(-100%);
        }

        100% {
          transform: translateX(100%);
        }
      }
    }
  }

  :deep(.el-upload-list--picture-card .el-upload-list__item) {
    width: 100px;
    height: 100px;
    border-radius: 8px;

    // 优化图片预览效果
    &:hover {
      transform: translateY(-2px);
      box-shadow: 0 4px 10px rgba(0, 0, 0, 0.1);
    }
  }

  // 移动端样式优化
  &.mobile-upload {

    // 适应移动端上传按钮
    :deep(.el-upload--picture-card) {
      width: 90px;
      height: 90px;
      line-height: normal;
      display: flex;
      flex-direction: column;
      align-items: center;
      justify-content: center;
      margin-bottom: 8px;
      border-width: 1px;

      i {
        font-size: 24px;
        margin-bottom: 4px;
      }

      // 触摸动画
      &:active {
        transform: scale(0.96);
        background-color: #f0f0f0;
      }
    }

    // 移动端图片列表项样式
    :deep(.el-upload-list--picture-card .el-upload-list__item) {
      width: 90px;
      height: 90px;
      margin: 0 8px 8px 0;

      // 增大删除按钮触摸区域
      .el-upload-list__item-actions {
        .el-icon-delete {
          font-size: 16px;
        }
      }

      // 增大预览按钮触摸区域
      .el-icon-zoom-in {
        font-size: 16px;
      }
    }
  }
}

// 上传提示样式
.upload-tip {
  display: flex;
  align-items: center;
  gap: 6px;
  margin-bottom: 10px;
  color: #909399;
  font-size: 13px;
  transition: all 0.3s ease;

  @media screen and (max-width: 768px) {
    padding: 6px 8px;
    background-color: rgba(64, 158, 255, 0.08);
    border-radius: 6px;
    margin-bottom: 12px;
  }

  i {
    color: #409EFF;

    @media screen and (max-width: 768px) {
      font-size: 16px;
    }
  }
}

// 弹窗样式
:deep(.moment-dialog) {
  border-radius: 16px !important;
  box-shadow: 0 10px 30px rgba(0, 0, 0, 0.1);
  overflow: hidden; // 防止内容溢出圆角
  background: #fdfdfd;

  &.is-mobile {
    width: 95vw !important;
    max-width: 95vw;
    height: 95vh;
    margin-top: 2.5vh !important;
    display: flex;
    flex-direction: column;
  }

  .el-dialog__header {
    padding: 16px 24px;
    border-bottom: 1px solid #f0f0f0;
    margin-right: 0;
    position: relative;
    flex-shrink: 0;

    .moment-dialog__header {
      display: flex;
      align-items: center;
      gap: 12px;
      font-size: 16px;
      font-weight: 600;
      color: #303133;
    }

    .moment-dialog__close {
      position: absolute;
      top: 50%;
      right: 24px;
      transform: translateY(-50%);
      width: 30px;
      height: 30px;
      display: flex;
      align-items: center;
      justify-content: center;
      border-radius: 50%;
      cursor: pointer;
      transition: all 0.2s ease;
      color: #909399;

      &:hover {
        background-color: #f0f2f5;
        color: #606266;
      }

      i {
        font-size: 16px;
      }
    }
  }

  .el-dialog__body {
    padding: 0 !important;
    overflow: hidden !important;
    flex: 1;
    display: flex;
  }
}

.moment-dialog-body-wrapper {
  flex: 1;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.moment-dialog__content {
  flex: 1;
  overflow-y: auto;
  padding: 20px 24px;
  background-color: #fcfcfc;

  @media screen and (max-width: 768px) {
    padding: 12px 16px;
  }
}

.no-margin {
  margin-bottom: 0;
}

.editor-container {
  border: 1px solid #dcdfe6;
  border-radius: 8px;
  overflow: hidden;
  transition: all 0.3s ease;
  box-shadow: inset 0 1px 3px rgba(0, 0, 0, 0.02);


  &:hover,
  &:focus-within {
    border-color: var(--primary);
    box-shadow: 0 0 0 3px rgba(64, 158, 255, 0.1),
      inset 0 1px 3px rgba(0, 0, 0, 0.02);
  }

  .w-e-toolbar {
    border-bottom: 1px solid #e8e8e8 !important;
    background-color: #fafafa;
  }

  .editor-content-area {
    overflow-y: auto;

    .w-e-text-container {

      // 确保 placeholder 样式生效
      [data-slate-editor] p[data-slate-string] {
        background-color: transparent !important;
      }
    }
  }

  &.mobile-editor {
    border-radius: 8px;
    display: flex;
    flex-direction: column;
    height: 100%;
  }
}

.upload-wrapper {
  margin-top: 20px;
  padding: 16px;
  background-color: #fafbfd;
  border-radius: 8px;
  border: 1px dashed #e4e7ed;
}

.upload-tip {
  font-size: 13px;
  color: #909399;
  margin-bottom: 12px;
  display: flex;
  align-items: center;
  gap: 6px;

  i {
    color: #a9aeb8;
  }
}

.upload-images {
  .el-upload--picture-card {
    border-radius: 8px;
    width: 100px;
    height: 100px;
    line-height: 108px;
  }

  .el-upload-list__item {
    border-radius: 8px;
    width: 100px;
    height: 100px;
  }
}

.moment-dialog__footer-custom {
  padding: 16px 24px;
  border-top: 1px solid #f0f0f0;
  background-color: #fdfdfd;
  display: flex;
  justify-content: flex-end;
  align-items: center;
  gap: 12px;
  flex-shrink: 0;
}


// 移动端适配
:deep(.moment-dialog.is-mobile) {

  .el-dialog__header {
    padding: 12px 16px;

    .moment-dialog__close {
      right: 16px;
    }
  }

  .editor-content-area {
    flex: 1;
    min-height: 150px;
  }

  .upload-wrapper {
    padding: 12px;
  }

  .upload-images {

    .el-upload--picture-card,
    .el-upload-list__item {
      width: 72px;
      height: 72px;
      line-height: 80px;
    }
  }

  .moment-dialog__footer-custom {
    padding: 12px 16px;

    .el-button {
      flex: 1;
      font-size: 15px;
      height: 40px;
      padding: 0;
    }
  }
}

/* 修复 wangeditor 移动端菜单面板问题 */
.w-e-panel-container {
  @media screen and (max-width: 768px) {

    // 面板容器
    .w-e-panel {
      width: auto !important;
      max-width: calc(95vw - 32px) !important; // 确保不超出屏幕
      left: 50% !important;
      transform: translateX(-50%);
    }

    // 表情面板
    .w-e-panel-content-emotion {
      display: grid !important;
      grid-template-columns: repeat(auto-fill, minmax(36px, 1fr)); // 响应式网格
      gap: 8px;
      padding: 10px !important;

      .w-e-item {
        width: 100% !important;
        height: 36px !important;
        font-size: 24px !important;
      }
    }

    // 颜色选择面板
    .w-e-panel-content-color {
      display: grid !important;
      grid-template-columns: repeat(auto-fill, minmax(30px, 1fr)) !important;
      gap: 6px;
      padding: 10px !important;

      .w-e-item {
        width: 30px !important;
        height: 30px !important;
      }
    }
  }
}

.add-moment-btn-section {
  display: flex;
  flex-direction: column;
  align-items: center;
  margin-bottom: 32px;
  width: 100%;
}

.no-moments-tip {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 60px 20px;
  text-align: center;
  border-radius: 16px;
  background: linear-gradient(145deg, #f9fbfd, #f0f4f8);
  box-shadow: 0 10px 20px rgba(0, 0, 0, 0.03);
  margin: 30px 0;

  i {
    font-size: 48px;
    color: #409EFF;
    margin-bottom: 16px;
    opacity: 0.8;
  }

  p {
    font-size: 16px;
    color: #606266;
    margin-bottom: 20px;
  }

  .el-button {
    padding: 10px 24px;
    font-weight: 500;
  }

  @media (prefers-color-scheme: dark) {
    background: linear-gradient(145deg, #1f2022, #1a1b1f);
    box-shadow: 0 10px 20px rgba(0, 0, 0, 0.1);

    i {
      color: #1890ff;
    }

    p {
      color: #c0c0c0;
    }
  }

  .dark-mode & {
    background: linear-gradient(145deg, #1f2022, #1a1b1f);
    box-shadow: 0 10px 20px rgba(0, 0, 0, 0.1);

    i {
      color: #1890ff;
    }

    p {
      color: #c0c0c0;
    }
  }
}

.section-divider {
  position: relative;
  width: 100%;
  text-align: center;
  margin-top: 24px;
  margin-bottom: 24px;

  &:before {
    content: '';
    position: absolute;
    top: 50%;
    left: 0;
    width: 100%;
    height: 1px;
    background: linear-gradient(90deg, transparent, rgba(0, 0, 0, 0.06) 20%, rgba(0, 0, 0, 0.06) 80%, transparent);
  }

  span {
    position: relative;
    background: var(--card-bg, #fff);
    padding: 0 18px;
    font-size: 16px;
    color: #606266;
    font-weight: 600;
    letter-spacing: 1px;
    text-shadow: 0 1px 0 rgba(255, 255, 255, 0.8);

    &:before,
    &:after {
      content: '';
      display: inline-block;
      width: 5px;
      height: 5px;
      border-radius: 50%;
      background-color: var(--primary, #409EFF);
      margin: 0 8px;
      vertical-align: middle;
      opacity: 0.8;
    }
  }

  /* 暗黑模式适配 */
  @media (prefers-color-scheme: dark) {
    &:before {
      background: linear-gradient(90deg, transparent, rgba(255, 255, 255, 0.15) 20%, rgba(255, 255, 255, 0.15) 80%, transparent);
    }

    span {
      background: var(--card-bg, #1f2022);
      color: #e0e0e0;
      text-shadow: 0 1px 2px rgba(0, 0, 0, 0.3);

      &:before,
      &:after {
        background-color: var(--primary, #1890ff);
      }
    }
  }

  /* 自定义暗黑模式类 */
  .dark-mode & {
    &:before {
      background: linear-gradient(90deg, transparent, rgba(255, 255, 255, 0.15) 20%, rgba(255, 255, 255, 0.15) 80%, transparent);
    }

    span {
      background: var(--card-bg, #1f2022);
      color: #e0e0e0;
      text-shadow: 0 1px 2px rgba(0, 0, 0, 0.3);

      &:before,
      &:after {
        background-color: var(--primary, #1890ff);
      }
    }
  }
}

.moments-list {
  position: relative;
  padding-top: 8px;

  &::before {
    content: '';
    position: absolute;
    top: -5px;
    left: 50%;
    transform: translateX(-50%);
    width: 80px;
    height: 5px;
    border-radius: 5px;
    background-color: rgba(0, 0, 0, 0.03);
  }

  /* 暗黑模式适配 */
  @media (prefers-color-scheme: dark) {
    &::before {
      background-color: rgba(255, 255, 255, 0.05);
    }
  }

  /* 自定义暗黑模式类 */
  .dark-mode & {
    &::before {
      background-color: rgba(255, 255, 255, 0.05);
    }
  }
}

// 编辑器容器样式
.editor-container {
  border: 1px solid #dcdfe6;
  border-radius: 8px;
  overflow: hidden;
  margin-bottom: 10px;
  transition: all 0.3s ease;
  position: relative; // 添加相对定位

  // 移动端特定样式
  &.mobile-editor {
    border-width: 1px;
    border-radius: 6px;

    // 移动端工具栏样式
    :deep(.w-e-toolbar) {
      flex-wrap: wrap; // 让工具栏自动换行
      padding: 6px 4px !important;
      overflow-x: auto; // 允许横向滚动
      justify-content: flex-start; // 从左到右排列

      // 美化滚动条
      &::-webkit-scrollbar {
        height: 4px;
        width: 4px;
      }

      &::-webkit-scrollbar-thumb {
        background: rgba(0, 0, 0, 0.2);
        border-radius: 2px;
      }

      &::-webkit-scrollbar-track {
        background: rgba(0, 0, 0, 0.05);
      }

      // 工具栏项目样式
      .w-e-bar-item {
        padding: 4px !important;
        margin-right: 2px !important;
        flex-shrink: 0; // 禁止压缩
      }

      .w-e-bar-divider {
        height: 18px !important;
        margin: 0 3px !important;
        flex-shrink: 0; // 禁止压缩
      }

      // 工具按钮触摸区域增大
      .w-e-bar-item-button {
        min-width: 32px;
        min-height: 32px;
        display: flex;
        align-items: center;
        justify-content: center;
      }
    }

    // 移动端文本区域样式
    :deep(.w-e-text-container) {
      // 高度在JS中动态计算
      overflow-y: auto !important;
      background-color: #fff;

      // 编辑区滚动条样式
      .w-e-scroll {
        padding: 10px !important;

        // 美化滚动条
        &::-webkit-scrollbar {
          width: 4px;
        }

        &::-webkit-scrollbar-thumb {
          background: rgba(0, 0, 0, 0.2);
          border-radius: 2px;
        }

        &::-webkit-scrollbar-track {
          background: rgba(0, 0, 0, 0.05);
        }

        // 提高输入区域的可点击区域
        .w-e-text {
          min-height: 150px; // 确保有足够高度可编辑
        }
      }
    }

    // 移动端上传按钮样式优化
    :deep(.w-e-bar-item[data-title="上传图片"]) {
      .w-e-bar-item-button {
        background-color: rgba(64, 158, 255, 0.1);
        border-radius: 4px;
      }
    }

    // 移动端插入表情样式优化
    :deep(.w-e-bar-item[data-title="表情"]) {
      .w-e-bar-item-button {
        background-color: rgba(255, 193, 7, 0.1);
        border-radius: 4px;
      }
    }
  }

  // 通用样式
  :deep(.w-e-toolbar) {
    border: none !important;
    background-color: #f5f7fa !important;
    padding: 8px !important;

    .w-e-bar-item {
      margin-right: 5px !important;
    }

    .w-e-bar-divider {
      height: 20px !important;
      margin: 0 8px !important;
    }

    // 添加工具栏激活状态样式
    .w-e-bar-item-active {
      background-color: rgba(64, 158, 255, 0.15) !important;
      border-radius: 4px;
    }
  }

  // 编辑区域样式
  :deep(.w-e-text-container) {
    border: none !important;
    height: 300px !important;

    &.mobile-height {
      height: 250px !important; // 移动端稍微降低高度
    }

    // 编辑区域内容样式
    .w-e-scroll {
      padding: 12px 16px !important;

      @media screen and (max-width: 768px) {
        padding: 10px 12px !important;
      }

      // 编辑区域内容
      .w-e-text {
        font-size: 15px;
        line-height: 1.6;

        // 移动端字体稍大一些，更易点击
        @media screen and (max-width: 768px) {
          font-size: 16px;
          line-height: 1.5;
        }

        // 增强代码块在移动端的显示效果
        pre {
          overflow-x: auto;
          background-color: #1e2127;
          color: #d4d4d4;
          border-radius: 4px;

          @media screen and (max-width: 768px) {
            font-size: 14px;
            padding: 8px;
          }
        }

        // 增强表格在移动端的滚动效果
        table {
          min-width: 100%;
          overflow-x: auto;
          display: block;
          max-width: 100%; // 确保不超出容器

          @media screen and (max-width: 768px) {
            font-size: 14px;
          }
        }
      }
    }
  }

  // 添加底部渐变提示，表示可滚动
  &.mobile-editor:after {
    content: '';
    position: absolute;
    bottom: 0;
    left: 0;
    right: 0;
    height: 20px;
    background: linear-gradient(to bottom, rgba(255, 255, 255, 0), rgba(255, 255, 255, 0.8));
    pointer-events: none; // 避免阻碍点击
    opacity: 0.8;
    z-index: 100;
  }
}

// 移动端对话框弹窗样式优化
@media screen and (max-width: 768px) {
  :deep(.moment-dialog) {
    width: 95% !important;
    margin-top: 50px !important;

    .el-dialog__body {
      padding: 15px !important;
    }

    .el-form-item__label {
      padding-bottom: 5px;
      width: 100% !important;
      text-align: left;
      float: none;
    }

    .el-form-item__content {
      margin-left: 0 !important;
    }

    // 底部按钮优化
    .el-dialog__footer {
      padding: 10px 15px !important;
      display: none !important; // 在移动端隐藏原有底部按钮区域
    }
  }
}

// 添加移动端弹窗底部固定操作按钮样式
.mobile-dialog-footer {
  position: sticky;
  bottom: 0;
  left: 0;
  right: 0;
  padding: 12px 15px;
  background: rgba(255, 255, 255, 0.95);
  backdrop-filter: blur(5px);
  border-top: 1px solid #ebeef5;
  z-index: 10;
  display: flex;
  flex-direction: column;
  gap: 10px;
  box-shadow: 0 -2px 10px rgba(0, 0, 0, 0.05);
  margin-top: 15px;

  .el-button {
    height: 40px;
    font-size: 16px;
    border-radius: 8px;

    &--primary {
      margin-bottom: 8px;
      background: linear-gradient(135deg, var(--primary, #409EFF) 0%, #4dabf7 100%);
      border-color: transparent;
      font-weight: 500;

      &:active {
        background: var(--primary, #409EFF);
        transform: translateY(1px);
      }
    }
  }
}

/* 暗黑模式适配 */
@media (prefers-color-scheme: dark) {
  .mobile-dialog-footer {
    background: rgba(30, 30, 30, 0.95);
    border-top-color: #3e3e3e;
  }
}

/* 自定义暗黑模式类 */
.dark-mode {
  .mobile-dialog-footer {
    background: rgba(30, 30, 30, 0.95);
    border-top-color: #3e3e3e;
  }
}

// 添加查看详情链接样式
.moment-detail-link {
  display: flex;
  align-items: center;
  justify-content: center;
  margin-top: 12px;
  padding: 8px 0;
  color: var(--primary, #409EFF);
  font-size: 14px;
  cursor: pointer;
  transition: all 0.3s ease;
  border-top: 1px dashed rgba(0, 0, 0, 0.06);

  i {
    margin-left: 4px;
    font-size: 12px;
    transition: transform 0.3s ease;
  }

  &:hover {
    color: #1890ff;
    text-decoration: underline;

    i {
      transform: translateX(3px);
    }
  }

  /* 暗黑模式适配 */
  @media (prefers-color-scheme: dark) {
    border-top-color: rgba(255, 255, 255, 0.06);

    &:hover {
      color: #40a9ff;
    }
  }

  /* 自定义暗黑模式类 */
  .dark-mode & {
    border-top-color: rgba(255, 255, 255, 0.06);

    &:hover {
      color: #40a9ff;
    }
  }
}

// 添加展开收起按钮的美化样式
.expand-collapse-btn {
  display: flex;
  align-items: center;
  gap: 8px;
  margin: 12px auto 0;
  padding: 8px 18px;
  background: linear-gradient(135deg, rgba(64, 158, 255, 0.1) 0%, rgba(100, 181, 255, 0.15) 100%);
  color: var(--primary, #409EFF);
  border-radius: 30px;
  font-size: 14px;
  width: fit-content;
  cursor: pointer;
  transition: all 0.3s cubic-bezier(0.25, 0.46, 0.45, 0.94);
  position: relative;
  overflow: hidden;
  font-weight: 500;
  border: 1px solid rgba(64, 158, 255, 0.2);
  box-shadow: 0 3px 8px rgba(64, 158, 255, 0.1);

  &:hover {
    transform: translateY(-2px);
    background: linear-gradient(135deg, rgba(64, 158, 255, 0.15) 0%, rgba(100, 181, 255, 0.2) 100%);
    box-shadow: 0 5px 15px rgba(64, 158, 255, 0.15);
  }

  &:active {
    transform: translateY(0);
    box-shadow: 0 2px 5px rgba(64, 158, 255, 0.1);
  }

  i {
    margin-left: 3px;
    font-size: 14px;
    transition: transform 0.3s ease;
  }

  &:hover i {
    transform: translateY(2px) scale(1.1);
  }

  .expand-btn-shine {
    position: absolute;
    top: 0;
    left: -150%;
    width: 100%;
    height: 100%;
    background: linear-gradient(90deg,
        rgba(255, 255, 255, 0) 0%,
        rgba(255, 255, 255, 0.4) 50%,
        rgba(255, 255, 255, 0) 100%);
    animation: button-shine 3s infinite ease-in-out;
    transform: skewX(-20deg);
    pointer-events: none;
  }

  @keyframes button-shine {
    0% {
      left: -150%;
    }

    50%,
    100% {
      left: 150%;
    }
  }

  /* 暗黑模式适配 */
  @media (prefers-color-scheme: dark) {
    background: linear-gradient(135deg, rgba(24, 144, 255, 0.15) 0%, rgba(24, 160, 255, 0.2) 100%);
    border: 1px solid rgba(24, 144, 255, 0.25);
    box-shadow: 0 3px 8px rgba(0, 0, 0, 0.2);

    &:hover {
      background: linear-gradient(135deg, rgba(24, 144, 255, 0.2) 0%, rgba(24, 160, 255, 0.25) 100%);
      box-shadow: 0 5px 15px rgba(0, 0, 0, 0.3);
    }
  }

  /* 自定义暗黑模式类 */
  .dark-mode & {
    background: linear-gradient(135deg, rgba(24, 144, 255, 0.15) 0%, rgba(24, 160, 255, 0.2) 100%);
    border: 1px solid rgba(24, 144, 255, 0.25);
    box-shadow: 0 3px 8px rgba(0, 0, 0, 0.2);

    &:hover {
      background: linear-gradient(135deg, rgba(24, 144, 255, 0.2) 0%, rgba(24, 160, 255, 0.25) 100%);
      box-shadow: 0 5px 15px rgba(0, 0, 0, 0.3);
    }
  }
}
</style>